views:

3910

answers:

5

I have an animation that I'm displaying using a UIImageView:

imageView.animationImages = myImages;
imageView.animationDuration = 3;
[imageView startAnimating];

I know I can stop it using stopAnimating, but what I want is to be able to pause it. The reason is that when you call stop, none of your animation images are displayed, whereas I would like the last one that is up at the time when I hit a button to stay up.

I have tried setting the duration to a much larger number, but that causes all the images to disappear as well. There must be a really basic way to do this?

A: 

Maybe you can take a screenshot of the last animated image and display that?

Dan
+4  A: 

Hmmm...since no one seems to know I guess it's not possible.

I went ahead and wrote my own UIView, with a UIImageView subview, that uses an NSTimer to switch between images. The advantage of this is that I can pause and resume the timer at my leisure, and performance doesn't seem to be an issue.

rustyshelf
+7  A: 

This code will pause an animated object at its current position in the animation process. If you record other variables like the time or progress or whatever you need, it should be fairly trivial to resume the animation again.

UIView *viewBeingAnimated = //your view that is being animated
viewBeingAnimated.frame = [[viewBeingAnimated.layer presentationLayer] frame];
[viewBeingAnimated.layer removeAllAnimations];
//when user unpauses, create new animation from current position.
mazniak
Accepted answer
Bryan
A: 

Another option is to set the image property as well as the animationImages property. Doing this will display the static image when the UIImageView has its animations stopped.

Assuming your class is a subclass of UIImageView and have an NSMutableArray of images, do the following:

self.animationImages = images;
//yes, I'm skipping the step to check and make sure you have at least one
//element in your array
self.image = [images objectAtIndex: 0];
oddmeter
Found this doesn't work on iOS 4.0
Typeoneerror
A: 

check out this link UIImageView Animation of images nice answer http://cocoabugs.blogspot.com/2010/08/uiimageview-animation-of-images.html

jeeva