开发者

iphone animation - catch notification

I'm using following li开发者_Python百科nes of code to animate:

CATransition *animation = [self getAnimation:dirString];
    [[self view] exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
    [[[self view] layer] addAnimation:animation forKey:kAnimationKey];

After end of animation, I want to play sound. How can I get notification when animation is completed?


CATransition is a subclass of CAAnimation, so it inherits (among other things) a delegate property, and a delegate method called animationDidStop:finished:. Define that method in whatever class you'd like to handle the event, and set the delegate property of the animation to an object of that class. When the animation finishes, the animationDidStop:finished: message is sent to the delegate.

For example:

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];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜