Cocoa animationImages finish detection

前端 未结 3 2065
半阙折子戏
半阙折子戏 2020-12-22 04:55

I\'m doing an animation using animationImages and animationRepeatCount = 1; How can I detect when the animation is done?

Thanks, Tee

相关标签:
3条回答
  • 2020-12-22 05:17

    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 讨论(0)
  • 2020-12-22 05:20

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

    0 讨论(0)
  • 2020-12-22 05:21

    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.

    0 讨论(0)
提交回复
热议问题