Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display animated GIF in iOS

I noticed that with iMessage, animated gifs can now be sent and displayed. Does this mean that Apple is now supporting the display of animated GIFs in an application, or is the easiest method still to split the image in frames and then sequentially show them? What is the easiest way to display an animated GIF as of iOS 5.1?

Thanks!

like image 767
swickblade Avatar asked Mar 16 '12 21:03

swickblade


People also ask

How do I view animated GIFs on my iPhone?

Launch the Photos app from your Home screen. Tap Albums along the bottom of the screen. Tap Animated to view your GIFs.


1 Answers

If you are targeting iOS7 and already have the image split into frames you can use animatedImageNamed:duration:.

Let's say you are animating a spinner. Copy all of your frames into the project and name them as follows:

  • spinner-1.png
  • spinner-2.png
  • spinner-3.png
  • etc.,

Then create the image via:

[UIImage animatedImageNamed:@"spinner-" duration:1.0f]; 

From the docs:

This method loads a series of files by appending a series of numbers to the base file name provided in the name parameter. For example, if the name parameter had ‘image’ as its contents, this method would attempt to load images from files with the names ‘image0’, ‘image1’ and so on all the way up to ‘image1024’. All images included in the animated image should share the same size and scale.

like image 60
Joe Masilotti Avatar answered Oct 12 '22 03:10

Joe Masilotti