【问题标题】:GIF image not showGIF 图像不显示
【发布时间】:2017-02-13 16:29:01
【问题描述】:

我关注这个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 图像不显示。

【问题讨论】:

标签: ios objective-c gif


【解决方案1】:

使用这个库 ....

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

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

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

【讨论】:

  • 批准我的回答@Khuong
  • 不,只是投票给你的答案。因为我可以使用一些库来显示 gif 图像。
【解决方案2】:

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

【讨论】:

  • 嗨@Abhisheck Gupta,我已经尝试过你的代码,但没有显示gif图像。
  • @Khuong 为我工作。你在哪里遇到问题??
  • 啊,好的。但是 gif 的框架显示不正确。
  • 对我来说,使用 UIWebView 显示 GIF 有点过头了,因为 webview 的初始化时间很短,导致视图加载速度变慢,使用外部库更好
  • 好的,我想我会用这个github.com/Flipboard/FLAnimatedImage
【解决方案3】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-18
    • 2020-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-01
    • 2011-06-17
    相关资源
    最近更新 更多