views:

458

answers:

2

I have a basic spinning animation of the iPhone. Is there any way that I can "pause" the animation so that the position of the view will be maintained? I guess one way of doing this would be to cause the animation to "complete" instead of calling "remove" on it, how would I do that?

CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2];
rotationAnimation.duration = 100;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = HUGE_VALF;
rotationAnimation.removedOnCompletion = NO;
rotationAnimation.fillMode = kCAFillModeForwards;
[myView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
+1  A: 

Set the current state of your view's layer to match the state of the presentationLayer, then remove the animation:

CALayer *pLayer = [myView.layer presentationLayer];
myView.layer.transform = pLayer.transform;
[myView.layer removeAnimationForKey:@"rotationAnimation"];
gerry3
Although this saves the position, it doesn't serve as the starting point when I re-add the animation to the view, the view moves slightly slower to accommodate for the shorter distance in the same amount of time. Is there another step that needs to be taken to be able to resume the animation where it left off?
mclaughlinj
+2  A: 

Recently appeared Apple's technical note QA1673 describes how to pause/resume layer's animation.

Vladimir