【发布时间】:2015-03-15 01:39:49
【问题描述】:
这是我用来为 CAShapeLayer 设置动画的代码:
_progressBarLayer.strokeEnd = CGFloat(_progressToDrawForProgress(progress))
let progressAnimation = CABasicAnimation(keyPath: "strokeEnd")
progressAnimation.duration = CFTimeInterval(1.0)
progressAnimation.fromValue = CGFloat(self.progress)
progressAnimation.toValue = _progressBarLayer.strokeEnd
progressAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn)
_progressBarLayer.addAnimation(progressAnimation, forKey: "progressAnimation")
我已经使用委托进行了测试,以查看动画是否播放,并且确实可以播放。记录在正确的位置开始和停止。
此代码在 setProgress(progress: CGFloat, animated: Bool) 函数中,如果动画为真,则运行。
这里有什么明显的地方吗?
【问题讨论】:
-
仅供参考,_progressBarLayer 是一个懒惰的
CAShapeLayer属性 -
会发生什么?什么都没有,还是立即跳到最终值?测试时CGFloat(self.progress)和_progressBarLayer.strokeEnd有什么值?
标签: ios animation cabasicanimation cashapelayer