Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does UIImageView cache images?

Probably I'm gonna ask the same question which was asked by other person (But it has no responses):
Speed up first UIImageView animation (force cache the images)

But, My short question is:
I have 60 images in resources, in timeinterval loop I'm gonna animate that images, each time setting to UIImageView.image the n'th image from resouce.

The problem is: first animation is bad! When I loop all images again in same UIImageView, animation is perfect. Can we pre cache images in UIImageView?

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

like image 616
Almas Adilbek Avatar asked Nov 25 '11 14:11

Almas Adilbek


People also ask

What is the difference between a UIImage and a UIImageView?

UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage .

What is image caching in Swift?

Cache is a hardware or software component that stores data so future requests for that data can be served faster; the data stored in a cache might be the result of an earlier computation, or the duplicate of data stored elsewhere.

What is use of UIImageView?

Overview. Image views let you efficiently draw any image that can be specified using a UIImage object. For example, you can use the UIImageView class to display the contents of many standard image files, such as JPEG and PNG files.


2 Answers

The method [UIImage imageNamed:@""] caches the image. The UIImageView doesn't. I had a problem in an app with a lot of images that was crashing due to low memory. To fix if I changed to [UIImage imageWithContentsOfFile:@""] that does not caches the image.

To pre-cache the image you can simply call [UIImage imageNamed:@""] for all images you want in the init method. But if you receive a memory warning the images gonna be deallocated.

like image 197
Bruno Domingues Avatar answered Nov 18 '22 03:11

Bruno Domingues


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

You can pre-load all of the images in an NSArray using [UIImage imageWithContensOfFile:@""]. Once you have the array, you can do what you want!

like image 45
Pablosproject Avatar answered Nov 18 '22 01:11

Pablosproject