iProRage
iProRage

Reputation: 424

How to know/test when an animation has finished playing

I am starting an animation via a button press. Here is the code for the button:

-(IBAction)startAnimation:(id)sender{
stick.animationImages = [NSArray arrayWithObjects:
                         [UIImage imageNamed:@"photo 1.JPG"],
                         [UIImage imageNamed:@"photo 2.JPG"],
                         [UIImage imageNamed:@"photo 3.JPG"],
                         [UIImage imageNamed:@"photo 4.JPG"],
                         [UIImage imageNamed:@"photo 5.JPG"],nil];
[stick setAnimationRepeatCount:200];
stick.animationDuration = 0.5;
[stick startAnimating];
}

and when the animation is done, i want to have a button appear, to play another animation on the screen. How can i test or see when my animation is done playing? Thanks in advance!

Upvotes: 1

Views: 549

Answers (2)

DarkDust
DarkDust

Reputation: 92335

You haven't told us what stick is, but it looks like a UIImageView. You can only call isAnimating to check whether the animation is still running but you don't get any notification and there's no delegate either. You can calculate the stop time (200 * 0.5) and thus set up a timer (add a little safety margin). This won't be 100% correct but it might be "good enough".

Upvotes: 2

Michael Dautermann
Michael Dautermann

Reputation: 89509

If you called your animation using blocks, you could use a completion block.

Here is a tutorial you can refer to which shows a couple different ways to call animation routines on iOS. This tutorial also shows what you can do for completion if you don't feel like using blocks (namely UIView's setAnimationDidStopSelector method).

Upvotes: -1

Related Questions