First, you should try using the same interval for both the afterDelay
parameter to performSelector
and the setAnimationDuration
(e.g., 0.7 seconds for both).
If that doesn't quite do what you want, you can programmatically call timer, constantly checking to see if the animation is done. For example, you could set up a display link (it's like a timer, but linked to updates to the display), and check imageView.isAnimating
, e.g.:
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (nonatomic, strong) CADisplayLink *displayLink;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.imageView.animationImages = @[[UIImage imageNamed:@"Rad_start_00000.png"],
[UIImage imageNamed:@"Rad_start_00001.png"],
[UIImage imageNamed:@"Rad_start_00002.png"],
[UIImage imageNamed:@"Rad_start_00003.png"],
[UIImage imageNamed:@"Rad_start_00004.png"],
[UIImage imageNamed:@"Rad_start_00005.png"],
[UIImage imageNamed:@"Rad_start_00006.png"],
[UIImage imageNamed:@"Rad_start_00007.png"],
[UIImage imageNamed:@"Rad_start_00008.png"],
[UIImage imageNamed:@"Rad_start_00009.png"],
[UIImage imageNamed:@"Rad_start_00010.png"],
[UIImage imageNamed:@"Rad_start_00011.png"],
[UIImage imageNamed:@"Rad_start_00012.png"],
[UIImage imageNamed:@"Rad_start_00013.png"],
[UIImage imageNamed:@"Rad_start_00014.png"],
[UIImage imageNamed:@"Rad_start_00015.png"],
[UIImage imageNamed:@"Rad_start_00016.png"],
[UIImage imageNamed:@"Rad_start_00017.png"]];
[self.imageView setAnimationDuration:0.7];
[self.imageView setAnimationRepeatCount:1];
[self.imageView startAnimating];
[self startDisplayLink];
}
- (void)startDisplayLink
{
self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(handleDisplayLink:)];
[self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
}
- (void)stopDisplayLink
{
[self.displayLink invalidate];
self.displayLink = nil;
}
- (void)handleDisplayLink:(CADisplayLink *)displayLink
{
if (!self.imageView.isAnimating) {
[self stopDisplayLink];
NSLog(@"done");
// do whatever else you want here
}
}
@end