UIImageView 是否缓存图像? [英] Does UIImageView cache images?

查看:24
本文介绍了UIImageView 是否缓存图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能我会问其他人问的同样问题(但没有回应):
加速第一个 UIImageView 动画(强制缓存图像)

但是,我的简短问题是:
我在资源中有 60 张图像,在时间间隔循环中,我要为这些图像设置动画,每次设置为 UIImageView.image 资源中的 n'th 图像.

问题是:第一个动画不好!当我在同一个 UIImageView 中再次循环所有图像时,动画是完美的.我们可以在 UIImageView 中预缓存图像吗?

或者我们可以制作一些技巧,使动画流畅?

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?

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

推荐答案

方法[UIImage imageNamed:@""]缓存图像.UIImageView 没有.我在一个包含大量图像的应用程序中遇到了问题,这些图像由于内存不足而崩溃.修复如果我更改为不缓存图像的 [UIImage imageWithContentsOfFile:@""].

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.

要预先缓存图像,您只需在 init 方法中为您想要的所有图像调用 [UIImage imageNamed:@""].但是,如果您收到内存警告,图像将被释放.

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.

这篇关于UIImageView 是否缓存图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆