我正在使用以下代码行来制作动画:
CATransition *animation = [self getAnimation:dirString];
[[self view] exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
[[[self view] layer] addAnimation:animation forKey:kAnimationKey];
动画结束后,我想播放声音。 动画完成后如何收到通知?
答案 0 :(得分:1)
CATransition是CAAnimation的子类,因此它继承(除其他外)一个delegate
属性和一个名为animationDidStop:finished:
的委托方法。在您想要处理事件的任何类中定义该方法,并将动画的delegate
属性设置为该类的对象。动画结束后,animationDidStop:finished:
消息将发送给代理人。
例如:
AnimationDelegate.m
@implementation AnimationDelegate
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
{
//Handle whatever needs to be done after the animation stops
}
ClassUsingAnimation.m
@implementation ClassUsingAnimation
{
AnimationDelegate *customDelegate = [[AnimationDelegate alloc] init];
CATransition *animation = [self getAnimation:dirString];
animation.delegate = customDelegate;
[[self view] exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
[[[self view] layer] addAnimation:animation forKey:kAnimationKey];
[customDelegate release];
}