CAShapeLayer’s strokeEnd doesn’t animate

筅森魡賤 提交于 2019-12-11 01:52:03

问题


This is the code I’m using to animate my 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")

I’ve tested using the delegate to see if the animation plays, and it does. Logging start and stop in the right place.

This code is in a setProgress(progress: CGFloat, animated: Bool) function and runs if animated is true.

Is there anything glaringly obvious here?


回答1:


Long answer: It turns out that the animation wasn’t playing because of something being drawn above the CAShapeLayer using quartz, so what I thought was the CAShapeLayer (that should be animated) was actually a Quartz drawing of that same layer.

Short answer: Don’t draw to the graphics context with Quartz



来源:https://stackoverflow.com/questions/29056332/cashapelayer-s-strokeend-doesn-t-animate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!