CAShapeLayer的strokeEnd没有动画
这是我用来动画我的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则运行。
这里有什么明显的东西吗?
答案很长:事实certificate动画没有播放是因为使用石英在CAShapeLayer上方绘制了一些东西,所以我认为CAShapeLayer(应该是动画的)实际上是同一层的Quartz绘图。
简短回答:不要使用Quartz绘制到图形上下文