Tutorial :animate rotation [duplicate]


Possible Duplicate:
Why CAAnimation Rotation is returning to previous state

I'm trying to animate a rotation using CATransform3DMakeRotation, but the problem is once the animation is finished, the image goes back to its initial position, i.e back to zero. But I'd like to keep it where it finished rotating. How would I do that?

edit What I'm trying to do is to create the same compass which comes with the new iPhone. Basically the locationmanager gives me new headings every few seconds (or several per second). Using the new heading and the timestamp, I was trying to get a smooth animation of the image but not getting anywhere. The only thing which seems to work is applying the transform directly, e.g.

compassimage.layer.transform = CATransform3DMakeRotation(newHeading.trueHeading *M_PI/180,0,0,1.0):   

but that's not animated...


You should set the animation.removedOncompletion to NO


Ok, back to basics, just trying to rotate an image by 90 degrees and keeping it there. Added the following code to - (void)viewDidLoad but even though it rotates it still going back to it's initial position once the animation is finished

CATransform3D rotationTransform = CATransform3DMakeRotation(M_PI, 0, 0, 1.0);

CABasicAnimation* rotationAnimation;  rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];  rotationAnimation.toValue = [NSValue valueWithCATransform3D:rotationTransform];  rotationAnimation.duration = 2.0f;  rotationAnimation.removedOnCompletion = NO;    [image.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];  


all you have to do is change the figure so that it is negative.

compassimage.layer.transform = CATransform3DMakeRotation(-newHeading.trueHeading *M_PI/180,0,0,1.0):  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »