I am using the following sample of code to spin (continuous rotation) an UIImageView:
CAKeyframeAnimation *theAnimation = [CAKeyframeAnimation animation];
theAnimation.values = [NSArray arrayWithObjects:
[NSValue valueWithCATransform3D:CATransform3DMakeRotation(0, 0,0,1)],
[NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0,0,1)],
[NSValue valueWithCATransform3D:CATransform3DMakeRotation(2*M_PI, 0,0,1)],
nil];
theAnimation.cumulative = YES;
theAnimation.duration = duration;
theAnimation.repeatCount = HUGE_VALF;
theAnimation.removedOnCompletion = YES;
[self.layer addAnimation:theAnimation forKey:@"transform"];
Now I want to change the speed of the rotation (means different duration) while the animation is displayed. The simplest way is to stop the animation and create a new one. The problem with doing so is, that the new animation will start at 0 degree and this causes a ugly jump when the speed of the spinning view changes.
How can I change the duration of the animation without interrupting it?
Save a reference to the previous rotation then use that as your starting value when creating the new animation.
For a little more in depth explanation as to why you should call [[self.layer presentationLayer] valueForKeyPath….. rather than [self.layer valueForKeyPath……. is explained in depth in the Core Animation Programming Guide. Since the rotation (transform) has already been animated you would need to check the values of the presented layer.
https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreAnimation_guide/Articles/CoreAnimationArchitecture.html