GIF图像无法显示

时间:2016-10-05 09:34:06

标签: ios objective-c gif

我按照post显示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图像没有显示出来。

3 个答案:

答案 0 :(得分:1)

您可以使用UIWebview加载GIF图像:

wc = New WebClient
str1 = wc.DownloadString("mywebsite.com/get_serials_notused.php")

使用我在我的应用中使用的代码:

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

或检查一下:

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

答案 1 :(得分:1)

使用此库....

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

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

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

答案 2 :(得分:0)

iOS不支持GIF图像,只有静态图像序列可以链接变为动画,在你的链接中他们也将它分割成多帧来做,你应该使用外部库直接在{{1}中播放GIF },检查awesome-ios

中的某个库