开发者

Cocoa animationImages finish detection

开发者 https://www.devze.com 2022-12-15 04:54 出处:网络
I\'m doing an animation using animationImages and animationRepeatCount = 1; How开发者_JAVA技巧 can I detect when the animation is done?

I'm doing an animation using animationImages and animationRepeatCount = 1; How开发者_JAVA技巧 can I detect when the animation is done?

Thanks, Tee


You don't get a notification when UIImageView animations are finished. You should use NSObject's performSelector:withObject:afterDelay: method to schedule some code to execute after the time is done, but it won't be perfect.


Set the setAnimationDidStopSelector: to a method that takes action when the animation stops.


Very old question, but I needed a fix now, this works for me:

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

精彩评论

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