How to show animation of an image on iphone

I have an animated gif (like this one ), when I show the image in 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 an iphone?

0


a source to share


3 answers


Here is the code I have in my current project. I have a loop to put standy2 images in standby7.png into an array. I am using imageWithContentsOfFile as it seems a little better when using memory.

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.

+2


a source


Divide it into separate PNG or JPG images, then load each frame in UIImageView

and use its animation techniques. Take a look at the documentation UIImageView

under Animating Images. It's pretty straightforward.



+1


a source


If you are exporting all frames to separate images, you can make a view UIImage

, set the property to a animationImages

value NSArray

containing all your frames, like UIImages

. Then call [imageView startAnimating]

.

Kyle

0


a source







All Articles