Cocoa setAnimationDidStopSelector

时间:2010-01-04 13:24:35

标签: iphone objective-c

目前我的代码工作正常

[UIView setAnimationDidStopSelector:@selector(animationDone:finished:context:)];

- (void)animationDone:(NSString *)animationID finished:(BOOL)finished context:(void *)context {
// do stuff here
}

记录animationID的值会给我一个空值。

如何将值传递给@selector?

我试过

[UIView setAnimationDidStopSelector:@selector(animationDone:@"animation1"finished:context:)];

这给了我一个错误。

谢谢, 三通

1 个答案:

答案 0 :(得分:16)

传递给选择器的字符串是您在此方法调用中使用的字符串:

[UIView beginAnimations:@"your_animation_name_here" context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];
// whatever changes here
[UIView commitAnimations];

之后,你可以这样做:

- (void)animationFinished:(NSString *)animationID finished:(BOOL)finished context:(void *)context
{
    if ([animationID isEqualToString:@"your_animation_name_here"])
    {
        // something done after the animation
    }
}