How to animate an animated or non-animated Gif or any other images on iPhone development
Point to remember:
There is no possibility to directly apply an animated Gif or any other image in project resource and call UIImageView to animate it.
How do we achieve it?
There is a UIImageView property called 'animationImages', using which we can pass array of image frames and animated it as same as seeing gif animation on browser.
Steps:
1. Get your required animated gif image. Use some tools to extract that animated gif image to frame by frame images. I used Mac->Preview to launch my animated gif image, it will automatically show frames of images, choosing each one and do Save As to have frame of images in JPG format.
2. Add all the frame of gif images into your project resource folder in Xcode.
3. create an UImageView in your application screen.
4. Use the following code to make the animation:
UIImageView *myImageView;
myImageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:firstImgStr],[UIImage imageNamed:secondImgStr], [UIImage imageNamed:thirdImgStr], [UIImage imageNamed:fourthImgStr], nil];
myImageView.animationDuration = 1.0f;
myImageView.animationRepeatCount = 0;
[myImageView startAnimating];
[myImageView release];
Run this code and you can see the animated gif doing animation on screen in your UImageView.
Note: I added just four frame of images there such as firstImgStr, secondImgStr etc. you can add how many frame of images that you require.
Cheers!
M.P.Prabakar
Senior Systems Analyst.
Have fun and be addictive by playing "TossRing" marvelous iPhone game. Link is below..
am having one doubt.I implemented same code in my application.am using around 50 images in the array.my app is working fine in simulator.but it is not running in iphone device...it is showing status 10 exist error and terminated...
ReplyDeleteMy project requirement is just moving sequence of images one by one..
can u give solution for that problem....