UIImageView cache images?

Perhaps I will ask the same question that the other person asked (but he has no answers):
Speed ​​up the first UIImageView animation (force image caching)

But, my short question is:
I have 60 images in resources, in a timeinterval loop I am going to animate these images, each time setting the UIImageView.image image n'th from resouce .

The problem is that the first animation is bad! When I loop all the images in the same UIImageView again, the animation is beautiful. Can we pre-cache images in a UIImageView?

EDIT: Or maybe we can do some tricks to make the animation smooth?

+7
source share
3 answers

The [UIImage imageNamed:@""] method caches the image. UIImageView does not do this. I had a problem with an application with a lot of images that were crashing due to low memory. Fix if I changed to [UIImage imageWithContentsOfFile:@""] , which does not cache the image.

To pre-cache an image, you can simply call [UIImage imageNamed:@""] for all the images you want to use in the init method. But if you get a warning that the images will be deleted.

+17
source

UIImageView does not cache the image as it does [UIImage imageNamed:@""] . Unfortunately, if you have many images, imageNamed will crash your application because it runs out of memory.

You can preload all images in NSArray using [UIImage imageWithContensOfFile:@""] . When you have an array, you can do what you want!

+4
source

No, UIImageView does not cache images. image property is declared as a hold, so when you set a new image, then imageView sends a release message to the old image and retain to the new one.

The easiest way to animate a UIImageView is to set an array of images to the animationImages property and call the startAnimating method

 imageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"1.png"], ..., nil]; imageView.animationDuration = 2.0f; [imageView startAnimating]; 
+2
source

All Articles