Reputation: 939
I have an image I want to animate constantly in UIImageView. Like some image object to move left and right?
Thanks in advance.
Upvotes: 1
Views: 349
Reputation: 55604
Create the animation in a image editor (or something else if you already have the animation)
Then save each frame as an image. Create a folder in your Xcode project and import the files into it. (in the example below each frame is named "frame-x.png" where x is the frame number)
Then create an array of UIImages and set the UIImageView's animationImages
property to it:
imageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"frame-1"],
[UIImage imageNamed:@"frame-2"],
[UIImage imageNamed:@"frame-3"],
[UIImage imageNamed:@"frame-4"],
nil];
Where you have a UIImage for each frame. You then start the animation:
[imageView startAnimation];
You can also set the animationRepeatCount
property of the image view.
See the UIImageView Class Reference for more details.
Upvotes: 2