Twitter khuong291
Twitter khuong291

Reputation: 11672

GIF image not show

I follow this post to show GIF image.

I have tried:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
    animatedImageView.animationImages = [NSArray arrayWithObjects:
                                         [UIImage imageNamed:@"splash.gif"], nil];
    animatedImageView.animationDuration = 6.0f;
    animatedImageView.animationRepeatCount = 10;
    [animatedImageView startAnimating];
    [self.view addSubview: animatedImageView];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

I added GIF image to my project. But GIF image not show.

Upvotes: 1

Views: 1281

Answers (3)

Abhishek Gupta
Abhishek Gupta

Reputation: 601

You can use UIWebview to load GIF image :

NSString *pathForFile = [[NSBundle mainBundle] pathForResource: @"splash" ofType: @"gif"];
    NSData *dataOfGif = [NSData dataWithContentsOfFile: pathForFile];
    [Web_View loadData:dataOfGif MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];

Use code that I am using in my app :

NSString *pathForFile = [[NSBundle mainBundle] pathForResource: @"splash" ofType: @"gif"];
    NSData *dataOfGif = [NSData dataWithContentsOfFile: pathForFile];

        UIWebView *Web_View = [[UIWebView alloc] initWithFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height)];
    [Web_View loadData:dataOfGif MIMEType:@"image/gif" textEncodingName:@"" baseURL:[NSURL URLWithString:@""]];
        [self.view addSubview:Web_View];

or Check this :

https://github.com/mayoff/uiimage-from-animated-gif

Upvotes: 1

Himanshu Moradiya
Himanshu Moradiya

Reputation: 4815

Use this library ....

https://github.com/mayoff/uiimage-from-animated-gif

and put this code for load .gif file.

"YOURIMAGEVIEW".image = [UIImage animatedImageWithAnimatedGIFURL:"YOUR_URL_OF_IMAGE"]

Upvotes: 1

Tj3n
Tj3n

Reputation: 9923

iOS does not support GIF image, only sequence of static image that can chain to become animated, in your link they also split it to multiple frame to do it, you should use external library to play the GIF directly in UIImageView, check for some library in awesome-ios

Upvotes: 0

Related Questions