Using iPhone CALayer, I want a rotation animation for my spirit layer, but I also want a callback for the animation end, hot to do that?
I think maybe I should use CABasicAnimation, but I don't know how to do rotation using CABasicAnimation, any idea?
Thanks
If you set a delegate for a CAAnimation, you can add the callback method:
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
That gets called when the animation is complete. Look for examples of rotating animations via a CGAffineTransform transformation matrix, as per this link:
http://iphonedevelopment.blogspot.com/2008/10/demystifying-cgaffinetransform.html
As an aside, you can also do the same sort of a callback for a UIView animation by wrapping your call to rotate a UIView in the following block of code
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(rotationAnimationHasFinished:finished:context:)];
// Rotate the view here
[UIView commitAnimations];
and then defining a delegate method
- (void)rotationAnimationHasFinished:(NSString *)animationID finished:(BOOL)finished context:(void *)context;
{
// Handle the completion of the animation
}
within your delegate that will do whatever you need to after the animation has completed.