3

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.

ullstrm
  • 9,812
  • 7
  • 52
  • 83
  • It's equals. It's just two ways to call one method – Igor Sep 25 '15 at 12:19
  • @Igor Are you sure? Where would one find this in the documentation? It seems to me as if they are not the same, due to the fact that we can specify number of repeatCount's when doing this with an imageView. – ullstrm Sep 25 '15 at 12:22
  • documentation is on the apples official site https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImage_Class/ I'm sure on 99%, you use the set of files on file system to get the animation in both ways. So it should use the same code to proceed. And even if no you will have the same performance in both cases. To have better performance you should use the video(hard to change and support) or openGL animations directly – Igor Sep 25 '15 at 12:28

1 Answers1

4

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.

Community
  • 1
  • 1
MoDJ
  • 4,309
  • 2
  • 30
  • 65