I added an CAKeyframeAnimation with the Key "SpeedBoat" to a CALayer. Now I am trying to change the speed of the animation during the animation.
[[self.shipLayer animationForKey:@"SpeedBoat"] setSpeed:([[self.shipLayer animationForKey:@"SpeedBoat"] speed] + deltaTime)];
There seems to be an error in this line. But I do not get any debug informations. What is wrong here? Is it possible to change the speed of an ongoing animation?
It would be very nice if somebody could help me :)
Best regards xen
Yes, you can definitely change the speed of an animation. That's because
CAKeyframeAnimation
confirms to the protocolCAMediaTiming
.Apple explains this in their Animation Types and Timing Programming Guide.
Have a look at the section on Timing, Timespaces, and CAAnimation.
Specifically:
Could I also point you in the direction of some excellent videos that cover this? Have a look at:
WWDC 2010 Sessions 424 and 425 Core Animation in Practice Parts 1 and 2
WWDC 2011 Session 421 Core Animation Essentials
and
Developer Videos Session 716 Core Animation Techniques for iPhone and Mac
You can even change the speed of an animation to effectively "freeze" it. It's very useful for pausing and resuming. Although one caveat is that it won't behave properly if the app is backgrounded, or purged from memory. That you'll have to deal with manually.
See the Technical Q&A QA1673, and my answer to this question for more info on that process:
Is there an issue with updating a CALayer position while the layer is paused?