2016-10-05 110 views
1

我關注此post以顯示GIF圖像。GIF圖像不顯示

我曾嘗試:

#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 

我添加的GIF圖片到我的項目。但GIF圖像不顯示。

+0

看到這個曾經http://stackoverflow.com/questions/4386675/add-animated-gif-image-in-iphone-uiimageview –

+0

@ Anbu.Karthik,在同一條鏈路我提到的上方。 – Khuong

+0

噢好吧對不起,如果你想玩的單個gif使用UIWebview是最好的選擇 –

回答

0

iOS不支持GIF圖像,只有可以鏈接成爲動畫的靜態圖像序列,在你的鏈接中它們也將它分割爲多個幀來完成它,你應該使用外部庫直接在UIImageView中播放GIF,檢查一些庫awesome-ios

1

您可以使用一個UIWebView加載GIF圖像:

NSString *pathForFile = [[NSBundle mainBundle] pathForResource: @"splash" ofType: @"gif"]; 
    NSData *dataOfGif = [NSData dataWithContentsOfFile: pathForFile]; 
    [Web_View loadData:dataOfGif MIMEType:@"image/gif" textEncodingName:nil baseURL:nil]; 
,我用我的應用程序

使用代碼:

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]; 

或檢查:

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

+0

嗨@Abhisheck Gupta,我試過你的代碼,但gif圖像不顯示。 – Khuong

+0

@Khuong爲我工作。你在哪裏遇到問題? –

+0

啊,好的。但gif的框架顯示不正確。 – Khuong

1

使用這個庫....

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

,並把這個代碼加載.gif文件。

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

http://stackoverflow.com/users/4742830/khuong嘗試我的代碼。 –

+0

好的。使用庫是我的工作。 – Khuong

+0

批准我的答案@Khuong –