How to animate an image in iPhone app?
-
09-12-2019 - |
Question
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
Solution
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];
}
OTHER TIPS
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow