Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
343 views
in Technique[技术] by (71.8m points)

ios - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...