How to animate image like this using iPhone SDK?

animation, cocoa-touch, ios, iphone, objective-c

Solution

In iOS 5, you can use a sequence of images. First you will need to add a new category method:

Category

@interface UIImage (WrightsCS)
+(UIImage*)animatedImageWithImages:(NSArray*)images duration:(NSTimeInterval)duration;
@end

Example

+(UIImage*)loadingImage
{
    NSArray *animationFrames = [NSArray arrayWithObjects:
                                        [UIImage imageNamed:@"downloading01.png"],
                                        [UIImage imageNamed:@"downloading02.png"],
                                        [UIImage imageNamed:@"downloading03.png"],
                                        [UIImage imageNamed:@"downloading04.png"],
                                        [UIImage imageNamed:@"downloading05.png"],
                                        [UIImage imageNamed:@"downloading06.png"],
                                        [UIImage imageNamed:@"downloading07.png"],
                                        [UIImage imageNamed:@"downloading08.png"],
                                        [UIImage imageNamed:@"downloading09.png"],
                                        [UIImage imageNamed:@"downloading10.png"],
                                        [UIImage imageNamed:@"downloading11.png"],
                                        [UIImage imageNamed:@"downloading12.png"],
                                        [UIImage imageNamed:@"downloading13.png"],
                                        [UIImage imageNamed:@"downloading14.png"],
                                        [UIImage imageNamed:@"downloading15.png"],
                                        [UIImage imageNamed:@"downloading16.png"],
                                nil];
    return [UIImage animatedImageWithImages:animationFrames duration:1.0f];
}

Problem

Please check this app: Screenshot from that app is shown below: Can you please let me know how to add an image on touch and have each image animated?

Original source