UIImageView 是否缓存图像?

发布于 2024-12-18 04:37:45 字数 446 浏览 2 评论 0原文

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

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

问题是:第一部动画很糟糕!当我在同一个 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?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

迷你仙 2024-12-25 04:37:45

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

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

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.

扬花落满肩 2024-12-25 04:37:45

UIImageView 不会像 [UIImage imageNamed:@""] 那样缓存图像。不幸的是,如果您有大量图像,imageNamed 将使您的应用程序崩溃,因为它耗尽了内存。

您可以使用 [UIImage imageWithContensOfFile:@""] 预加载 NSArray 中的所有图像。
一旦你有了数组,你就可以做你想做的事了!

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!

死开点丶别碍眼 2024-12-25 04:37:45

不,UIImageView 不缓存图像。 image 属性声明为retain,因此当您设置新图像时,imageView 会向旧图像发送release 消息,并向新图像发送retain 消息。

动画 UIImageView 的最简单方法是将图像数组设置为属性 animationImages 并调用 startAnimating 方法

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

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

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

imageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"1.png"], ..., nil];
imageView.animationDuration = 2.0f;
[imageView startAnimating];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文