GIF图片未显示 [英] GIF image not show

查看:80
本文介绍了GIF图片未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照此帖子显示GIF图片.

I follow this post to show GIF image.

我尝试过:

#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图片无法显示.

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

推荐答案

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

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

或检查此内容:

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

这篇关于GIF图片未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆