views:

152

answers:

3

I have a UIImageView that is displaying a series of pictures as an animation. This part of the project works well.

I want to display a label when the animation ends. Is there an event that the Imageview will trigger when it's animation ends?

+1  A: 

Doesn't look like there is an event/delegate for this. My first instinct would be to calculate the length of the animation yourself, and then set up an NSTimer so that when the animation ends, NSTimer fires displaying whatever you want to display next.

Jaanus
+2  A: 

Set the duration the animation will go using setAnimationDuration: At the same time you configure performSelector:withObject:withDelay with the same delay as the duration the animation will go on

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0]; //the animation will last for 1.0s
//some animation code here
[UIView commitAnimations];
[self performSelector:@selector(someMethodToDisplayLabel) withObject:nil afterDelay:1.0];
    //someMethodToDisplayLabel will be called after 1.0s
Mihir Mathuria
Beautiful! Exactly what I wanted.
Chris
Well, UIImageView has its own startAnimating and stopAnimating methods to do the animation stuffs. I think that what Chris is using but not to call the UIView animation methods.I used some KVO tricks to try to listen to the value of "isAnimating" or "animating", it does not work. Since UIImageView has the animationDuration and animationRepeatCount properties, I think it is possible to estimate when will an animation stop (duration * repeat count).
zonble
Yep, my answer suggests to use these duration and repeat count properties to figure when to start your own animation.
Jaanus
A: 

hey Mihir Mathuria,

Thanks for ur reply, it worked for me !!! Thnx again....