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图像没有显示。

使用这个库….

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

并将此代码用于加载.gif文件。

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

您可以使用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

iOS不支持GIF图像,只能将链接的静态图像序列变为动画,在你的链接中它们也将它分割成多帧来做,你应该使用外部库直接在UIImageView播放GIF,检查一些库在令人敬畏的ios