Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animation End Callback for CALayer?

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

like image 299
zhongshu Avatar asked Jan 01 '09 13:01

zhongshu


2 Answers

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

like image 185
Kendall Helmstetter Gelner Avatar answered Oct 06 '22 00:10

Kendall Helmstetter Gelner


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.

like image 44
Brad Larson Avatar answered Oct 05 '22 22:10

Brad Larson