这是我用来制作动画的代码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)
函数并在动画为 true 时运行。
这里有什么显而易见的事情吗?
长答案:事实证明,动画没有播放是因为使用石英在 CAShapeLayer 上方绘制了某些内容,所以我认为 CAShapeLayer(应该是动画的)实际上是同一层的 Quartz 绘图。
简短的回答:不要使用 Quartz 绘制图形上下文
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)