tags:

views:

469

answers:

3

I have a animated gif ( like this one ) , when I show in an image view on my iphone app it just shows the first frame . This behavior is consistent with the apple documentation . I was wondering what is the best way to achieve this on the iphone ?

+1  A: 

Split it up into separate PNG or JPG images then load each frame into a UIImageView and use its animation methods. Take a look at the UIImageView documentation under "Animating Images." It's pretty straightforward.

Ramin
A: 

If you export all of the frames to individual images you can make a UIImage view, set the animationImages property to an NSArray containing all of your frames as UIImages. Then call [imageView startAnimating].

Kyle

Kyle
+2  A: 

Here's some code that I've got in a current project. I've got a loop to put images standy2 through to standby7.png into an array. Am using imageWithContentsOfFile since that seems to be a little better on memory usage.

standbyAnimationImages = [[NSMutableArray alloc] init];
for (NSUInteger i=2; i<=7; i++) {
    filename = [NSString stringWithFormat:@"standby%d", i];
    [standbyAnimationImages addObject:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:filename ofType:@"png"]]];
}

imageViewAnimation.animationImages = standbyAnimationImages;
imageViewAnimation.animationDuration = 2;
imageViewAnimation.animationRepeatCount = 0;
[imageViewAnimation startAnimating];

Hope this helps you.

Alistair