views:

406

answers:

3

Hello,

I have an animation using a UIImageView

myAnimatedView.animationImages = myImages;
myAnimatedView.animationDuration = 1;
myAnimatedView.animationRepeatCount = 1;
[myAnimatedView startAnimating];

How can I tell to animation to stop at the last frame or to be visible last frame of the series of images?

Thank you in advance

+2  A: 

After the animation finishes you can set your UIImageView image to the last frame of your animation.

myAnimatedView.image = [myAnimatedImages objectAtIndex:myAnimatedImages.count - 1]

I don't think there is a delegate method that would notify you on animationFinish event so you would need to start a NSTimer with same duration as the animation to get the notification.

UIImageViewAnimation documentation

texmex5
You can actually forget about the `NSTimer` - as long as your image is animating, the `animationImages` will display until the animation is finished, then the `image` will display.
pix0r
This actually no longer works on iOS4, FYI. Trying to figure out a workaround but my app works fine on 3. Seems like animationImages clears the image property now.
Typeoneerror
Same here, my application suddenly got buggy with iOS 4. And there is no delegate to let me put the correct image back again.
asandroq
+1  A: 

the image property on the UIImageView class has the following docs: "If the animationImages property contains a value other than nil, the contents of this property are not used."

So the trick to hold on the last frame of an animation in iOS4 is to first set the image property to that last frame (while animationImages is still nil), then set the animationImages property and call startAnimating. When the animation completes, the image property is then displayed. No callback/delegate needed.

Brian Bahner
A: 

Thanks Brian you answer worked!

Tom Sgro