CALayer的动画结束回调?

时间:2009-01-01 13:41:44

标签: cocoa-touch core-animation

使用iPhone CALayer,我想要一个旋转动画用于我的精神图层,但我也想要一个动画结束的回调,热门这样做?

我想也许我应该使用CABasicAnimation,但我不知道如何使用CABasicAnimation进行旋转,任何想法?

由于

2 个答案:

答案 0 :(得分:5)

如果为CAAnimation设置委托,则可以添加回调方法:

- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag

动画完成后调用它。根据以下链接查找通过CGAffineTransform转换矩阵旋转动画的示例:

http://iphonedevelopment.blogspot.com/2008/10/demystifying-cgaffinetransform.html

答案 1 :(得分:3)

顺便说一下,你也可以通过在下面的代码块中包含调用旋转UIView来为UIView动画做同样的回调

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(rotationAnimationHasFinished:finished:context:)];
// Rotate the view here
[UIView commitAnimations];

然后定义委托方法

- (void)rotationAnimationHasFinished:(NSString *)animationID finished:(BOOL)finished context:(void *)context;
{
// Handle the completion of the animation
}
在您的委托中

,它将在动画完成后执行您需要的任何操作。