iOS 中动画图像的最佳实践 - UIImage 或 UIImageView?

Best practice for animated image in iOS - UIImage or UIImageView?

抱歉,如果这个问题有点主观,但我找不到与该主题相关的任何信息。

问题很简单:

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

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

self.imageView.animationImages = listOfMyImageNames;

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

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

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