iPhone SDK - 如何判断动画何时完成?

Chr*_*man 5 iphone core-animation

我在触摸图像时开始动画放大,然后在释放图像时将其缩小到正常尺寸.通过使用setAnimationBeginsFromCurrentState:YES,如果您通过动画将手指抬起一部分,则缩放效果会很好并且平滑.

但是,如果你已经触摸图像足够长的时间以完成动画,我想要做的就是"锁定"更大的尺寸,但是如果你过早地释放它会让它恢复正常.

有没有办法判断当前是否正在运行动画,或者特定动画是否已完成?

我想我可以用performSelector执行此操作:afterDelay:调用touchesStarted,延迟等于动画的长度,如果touchesEnded过早就取消它,但我无法想象这是最好的方式......?

Ale*_*yne 13

- (void)animateStuff {
    [UIView beginAnimations:@"animationName" context:nil];
    [UIView setAnimationDelegate:self];
    [self.view doWhatever];
    [UIView commitAnimations];
}

- (void)animationDidStop:(NSString *)animationID
                finished:(NSNumber *)finished
                 context:(void *)context
{
    if ([finished boolValue]) {
        NSLog(@"Animation Done!");
    }
}
Run Code Online (Sandbox Code Playgroud)