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

两盒软妹~` 提交于 2019-12-11 03:43:11

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/32781415/best-practice-for-animated-image-in-ios-uiimage-or-uiimageview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!