Adam Carter
Adam Carter

Reputation: 4844

CAShapeLayer’s strokeEnd doesn’t animate

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?

Upvotes: 2

Views: 839

Answers (1)

Adam Carter
Adam Carter

Reputation: 4844

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

Upvotes: 1

Related Questions