Reputation: 3166
I am using the uiimage-from-animated-gif library to show an animated GIF through a UIImage
. It's working, but I need to stop the animation or stop showing imageView2
after one complete revolution.
I animate the GIF with the following code:
NSURL *url2 = [[NSBundle mainBundle] URLForResource:@"dove-animate" withExtension:@"gif"];
self.imageView2.image = [UIImage animatedImageWithAnimatedGIFData:[NSData dataWithContentsOfURL:url2]];
Upvotes: 1
Views: 1145
Reputation: 91
Add timer to disappear the imageview. Then it appears like animation stopped
{
NSTimer *timer;
timer = [NSTimer scheduledTimerWithTimeInterval: 4
target: self
selector: @selector(removeAnimation)
userInfo: nil
repeats: NO];
}
-(void)removeAnimation
{
imageview.hidden=yes;
}
Upvotes: 0
Reputation: 2542
There's no need to resort to gif's if you're storing the images in your bundle and not loading them from the web. You can actually have an entire folder of images (png's would be good quality and offer transparency). Then:
UIImage
via UIImage + imageNamed:
or similar.UIImageView
and set animationImages
to your array.startAnimating
and stopAnimating
on the image view as desired.Upvotes: 1
Reputation: 1201
If you know the animation duration then you can just set a static image to your image view after that duration.
For example, if the duration is 2 seconds, then
[self performSelector:@selector(stopAnimating) withObject:nil afterDelay:2.0f];
-(void)stopAnimating{
[self.imageView2 setImage:[UIImage imageNamed:@"dove-animate.gif"]];
}
Upvotes: 1