CAShapeLayer 的笔触结束不动画



这是我用来为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 绘制图形上下文

最新更新