2

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?

Adam Carter
  • 4,741
  • 5
  • 42
  • 103
  • Just FYI, _progressBarLayer is a lazy `CAShapeLayer` property – Adam Carter Mar 15 '15 at 01:41
  • What does happen? Nothing, or does it jump immediately to the final value? What values do CGFloat(self.progress) and _progressBarLayer.strokeEnd have when you test it? – rdelmar Mar 15 '15 at 05:05

1 Answers1

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

Adam Carter
  • 4,741
  • 5
  • 42
  • 103