OGeek|极客世界-中国程序员成长平台

标题: ios - CAShapeLayer 的 strokeEnd 没有动画 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 05:54
标题: ios - 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")

我已经使用委托(delegate)进行了测试,以查看动画是否播放,并且确实播放。记录在正确的位置开始和停止。

此代码在 setProgress(progress: CGFloat, animated: Bool) 函数中,如果动画为真,则运行。

这里有什么明显的地方吗?



Best Answer-推荐答案


长答案:事实证明,动画没有播放是因为使用 quartz 在 CAShapeLayer 上方绘制了一些东西,所以我认为 CAShapeLayer(应该是动画的)实际上是同一层的 Quartz 绘图。

简答:不要使用 Quartz 绘制到图形上下文

关于ios - CAShapeLayer 的 strokeEnd 没有动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29056332/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4