Animation End Callback for CALayer?

空扰寡人 提交于 2019-12-10 14:49:01

问题


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


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/404957/animation-end-callback-for-calayer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!