iOS 中动画图像的最佳实践 - UIImage 或 UIImageView? [英] Best practice for animated image in iOS - UIImage or UIImageView?

查看:74
本文介绍了iOS 中动画图像的最佳实践 - UIImage 或 UIImageView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抱歉,这个问题有点主观,但我找不到有关该主题的任何信息.

问题很简单:

以下哪个替代方案是最佳"(即最佳性能).无论选择哪种解决方案,我都想在 UIImageView 中显示图像.

self.imageView.image = [UIImage animationImageNamed:@"imagename-" duration:2.0f];

self.imageView.animationImages = listOfMyImageNames;self.imageView.animationRepeatCount = 0;self.imageView.animationDuration = 2;[self.imageView startAnimating];

我知道 UIImageView 解决方案在循环次数等方面提供了更大的灵活性,但我想要一个无限动画,所以在这种情况下这无关紧要.

解决方案

在您描述的两个选项中,animatedImageNamed 方法比尝试使用 animationImages 更好.原因是如果一系列图像太长或宽度和高度太大,animationImages 方法会使您的设备崩溃.问题在于,与具有更好内存限制的 animationImageNamed API 相比, animationImages 会以惊人的速度消耗内存.就 CPU 使用率和内存使用率而言,这两种方法实际上都不是最佳",因为有明显更好的实现可用.>

Sorry if the question is a bit subjective, but I couldn't find anything about the topic.

The question is simple:

Which one of the following alternatives are "best", (i.e. best performance). I want to show the image in an UIImageView regardless of the chosen solution.

self.imageView.image = [UIImage animatedImageNamed:@"imagename-" duration:2.0f];

or

self.imageView.animationImages = listOfMyImageNames;

self.imageView.animationRepeatCount = 0;
self.imageView.animationDuration = 2;
[self.imageView startAnimating];

I know that the UIImageView-solution gives more flexibility with number of loops etc, but I want an infinite animation so that doesn't matter in this case.

解决方案

Of the two options you describe, the animatedImageNamed approach is better than attempting to use animationImages. The reason is that the animationImages approach will crash your device if the series of images is too long or the width and height are too large. The problem is that animationImages will eat up memory at a shocking rate as opposed to the animatedImageNamed API which has a better memory bound. Neither approach is actually the "best" in terms of CPU usage and memory usage as there are significantly better implementations available.

这篇关于iOS 中动画图像的最佳实践 - UIImage 或 UIImageView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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