6

"Back in the day" animated GIFs were ubiquitous online.

They were simple to use - just pop em' in wherever you want an animated image.

I'd like to display an animated image within an iOS application (for example, a graphic illustrating a letter being opened from an envelope).

But, I'm not sure how to go about this.

Obviously I don't want to use an animated GIF.

A video of some sort seems like it might be the preferred solution. But, what about transparency? Also, what about the retina display?

Thanks.

DShah
  • 9,768
  • 11
  • 71
  • 127
Steve
  • 31,144
  • 19
  • 99
  • 122

4 Answers4

12

Here is a tutorial on animating UIImage in the iPhone SDK:

http://www.icodeblog.com/2009/07/24/iphone-programming-tutorial-animating-a-game-sprite/

Dair
  • 15,910
  • 9
  • 62
  • 107
  • +1 for the interesting suggestion. I can easily see how I might use this approach to animate an image using PNG "frames". Although, I'm a little surprised this is the preferred approach. – Steve Aug 28 '11 at 03:36
  • 1
    @Steve: It is the preferred approach; in fact, it's the only current non-manual non-video approach. Works well for smallish animations with a small number of frames, which is basically the animated-GIF use case (It doesn't scale especially well to large views with lots of frames.) – Ben Zotto Aug 28 '11 at 03:43
  • 1
    I've found another page describing the same approach. Maybe it will be useful: [Making GIF animating on iOS](http://www.alterplay.com/ios-dev-tips/2010/12/making-gif-animating-on-ios.html). – Gengis Mar 29 '12 at 21:28
  • See what I found out about showing animated gif in iOS. http://iosnotestoremember.blogspot.com/2013/01/showing-animated-gif-in-ios.html I hope this helps. – Glenn S Jan 10 '13 at 07:08
3

Flipboard just released their GIF library which is very performant and is used by several popular apps like Flipboard, Dropbox, Medium etc:

https://github.com/Flipboard/FLAnimatedImage

Chintan Patel
  • 3,175
  • 3
  • 30
  • 36
0

For future references, Eric's answer here is a better way to do it since it uses modern ImageIO.framework and is also available as a category on UIImageView.

Community
  • 1
  • 1
Chintan Patel
  • 3,175
  • 3
  • 30
  • 36
  • Well, use of ImageIO is better that other approaches. But, that code will still consume all memory when running it on a GIF with more than just 1 or 2 frames of image data. The real solution is to decode ahead of time and cache the decoded results on disk and not in memory. – MoDJ Nov 13 '14 at 09:31
0

You can use UIWebView to load html Page with in Bundle. GO TO File > New>Others > Empty > Enter File Name with Extension

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
     <title>QUALITY PLACEMENTS</title>

</head>
<body>
<div style="word-wrap: break-word !important; width: 300px;">
    <img width="100%" src="Surprice-0.gif"/>
   </div></body></html> 
    //IOS CODE 
     UIWebView* mywebview=[[UIWebView alloc]initWithFrame:CGRectMake(5, 50, 300, 300)];
            mywebview.scalesPageToFit = NO;
            mywebview.scrollView.hidden = NO;
            [mywebview setMultipleTouchEnabled:YES];
            NSURL* url=[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"greeting" ofType:@"html"]];
            [mywebview loadRequest:[NSURLRequest requestWithURL:url]];
Baljeet Singh
  • 453
  • 5
  • 15