python 构建网站-某课Python Flask实现构建视频网站

画代码

// MARK: - 跑马灯动画实现过程

func marqueeAnimation() {

let frontAnima = CABasicAnimation()

frontAnima.keyPath = "position"

frontAnima.fromValue = NSValue(CGPoint: CGPoint(x:  self.frontLabel.frame.width / 2 , y: self.frame.height / 2))

frontAnima.toValue = NSValue(CGPoint: CGPoint(x: -1 * self.frontLabel.frame.width / 2, y: self.frame.height / 2))

frontAnima.duration = self.time

frontAnima.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)

frontAnima.repeatCount = MAXFLOAT

let behindAnima = CABasicAnimation()

behindAnima.keyPath = "position"

behindAnima.fromValue = NSValue(CGPoint: CGPoint(x:  self.frontLabel.frame.width / 2 * 3 , y: self.frame.height / 2))

behindAnima.toValue = NSValue(CGPoint: CGPoint(x:  self.frontLabel.frame.width / 2, y: self.frame.height / 2))

behindAnima.duration = self.time

behindAnima.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)

behindAnima.repeatCount = MAXFLOAT

self.frontLabel.layer.addAnimation(frontAnima, forKey: "frontAnima")

self.behindLabel.layer.addAnimation(behindAnima, forKey: "behindAnima")

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

开始

// MARK: - 开始跑马灯动画

func start(){

if isRun == false {

isRun = true

isSuspend = false

frontLabel.layer.timeOffset = 0.0

behindLabel.layer.timeOffset = 0.0

frontLabel.layer.speed = 1.0

behindLabel.layer.speed = 1.0

frontLabel.layer.beginTime = 0.0

behindLabel.layer.beginTime = 0.0

marqueeAnimation()

}

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

停止

// MARK: - 停止跑马灯动画

func stop() {

if isRun {

isRun = false

frontLabel.layer.removeAnimationForKey("frontAnima")

behindLabel.layer.removeAnimationForKey("behindAnima")

}

}

1

2

3

4

5

6

7

8

暂停

// MARK: -  暂停动画

func suspend() {

if isRun && isSuspend == false {

isSuspend = true

let frontPauseTime = frontLabel.layer.convertTime(CACurrentMediaTime(), fromLayer: nil)

frontLabel.layer.speed = 0.0

frontLabel.layer.timeOffset = frontPauseTime

let behindPauseTime = behindLabel.layer.convertTime(CACurrentMediaTime(), fromLayer: nil)

behindLabel.layer.speed = 0.0

behindLabel.layer.timeOffset = behindPauseTime

}

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

继续

// MARK: - 继续动画

func continuation() {

if isRun && isSuspend {

isSuspend = false

let frontPauseTime = frontLabel.layer.timeOffset

frontLabel.layer.speed = 1.0

frontLabel.layer.timeOffset = 0.0

frontLabel.layer.beginTime = 0.0

let frontTimeSincePause = frontLabel.layer.convertTime(CACurrentMediaTime(), fromLayer: nil)  - frontPauseTime

frontLabel.layer.beginTime = frontTimeSincePause

let behindPauseTime = behindLabel.layer.timeOffset

behindLabel.layer.speed = 1.0

behindLabel.layer.timeOffset = 0.0

behindLabel.layer.beginTime = 0.0

let behindTimeSincePause = behindLabel.layer.convertTime(CACurrentMediaTime(), fromLayer: nil)  - behindPauseTime

behindLabel.layer.beginTime = behindTimeSincePause

}

}

---------------------

作者:kanxuexizhong

来源:CSDN

原文:https://blog.csdn.net/kanxuexizhong/article/details/85024255

版权声明:本文为博主原创文章,转载请附上博文链接!

---------------------

作者:weixin_44129414

来源:CSDN

原文:https://blog.csdn.net/weixin_44129414/article/details/85237015

版权声明:本文为博主原创文章,转载请附上博文链接!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值