Yuval Rimar
Yuval Rimar

Reputation: 1055

Simple animation as iphone app background

I want to make an animated background for iphone app. Something simple 5-6 frames changing in the loop. On the front there will be another animation running. How can this be done?

Upvotes: 4

Views: 2998

Answers (1)

Dan K.
Dan K.

Reputation: 1532

The easiest thing to do is probably to use the animationImages property of a UIImageView. Once you have the animationImages property correctly set up, just call startAnimating on your view. So your code would look something like:

imageView.animationImages = myNSArrayofUIImagesObjects;
imageView.animationDuration = 1; // by default this is equal to the number of images multiplied by 1/30th of a second
[imageView startAnimating];

An important thing to note is that you can't easily control how long each image is shown. But what you can do is use the same image in your NSArray of images multiple times. So, for example, you could have an NSArray of length 500, where the first 100 entries map to your first image, the second 100 entries map to your second image, etc. Make sure to minimize the amount of memory you're loading onto the heap by reusing the same UIImage object for each of your five or six images.

Upvotes: 6

Related Questions