iOSDev
iOSDev

Reputation: 3617

How to animate an image in iPhone app?

I have a simple image which I want to animate in up and down...How do I achieve it in iPhone app?

Please help

Thanks

Upvotes: 0

Views: 739

Answers (2)

WrightsCS
WrightsCS

Reputation: 50697

You can use an array of images and animate them in 1 UIImage:

iOS 5:

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

if ( SYSTEM_VERSION_GREATER_THAN(@"5.0") )
{
    NSArray *animationFrames = [NSArray arrayWithObjects:
                                [UIImage imageNamed:@"image_0.png"],
                                [UIImage imageNamed:@"image_1.png"],
                                [UIImage imageNamed:@"image_3.png"],
                                [UIImage imageNamed:@"image_4.png"], nil];

    UIImage * animatedImage = [UIImage animatedImageWithImages:animationFrames duration:2.0f];    
} 

Upvotes: 2

Abizern
Abizern

Reputation: 150565

Have you looked at any of the Core Animation documents?

What I would do is to create a CALayer, add the image to its contents. position it just outside the view. add it as a sublayer to the the UIView's layer and then set the position of this layer to be where you want it to animate to.

That should give you enough of a hint to get started. When you get the hang of that you can look at doing more complicated animations.

Upvotes: 0

Related Questions