Cocoa animationImages完成检测

时间:2010-01-04 14:01:09

标签: iphone objective-c

我正在使用animationImages和animationRepeatCount = 1进行动画制作; 如何检测动画何时完成?

谢谢, 三通

3 个答案:

答案 0 :(得分:3)

UIImageView动画完成后,您不会收到通知。您应该使用NSObject的performSelector:withObject:afterDelay:方法来安排一些代码在时间结束后执行,但它不会是完美的。

答案 1 :(得分:1)

setAnimationDidStopSelector:设置为动画停止时采取操作的方法。

答案 2 :(得分:1)

很老的问题,但我现在需要修复,这对我有用:

[CATransaction begin];
[CATransaction setCompletionBlock:^{
    DLog(@"Animation did finish.");
}];

UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.window.bounds];
imageView.animationDuration = 0.3 * 4.0;
imageView.animationImages = @[[UIImage AHZImageNamed:@"Default2"],
                              [UIImage AHZImageNamed:@"Default3"],
                              [UIImage AHZImageNamed:@"Default4"],
                              [UIImage AHZImageNamed:@"Default5"]];
imageView.animationRepeatCount = 1;
[self.window addSubview:imageView];

[imageView startAnimating];

[CATransaction commit];