美文网首页
iOS加载gif图片

iOS加载gif图片

作者: 薄凉_简书 | 来源:发表于2017-05-16 12:26 被阅读113次

1、通过拆分gif,加载一个图片数组(推荐一个Mac APP自动拆分gif:Gif Preview)

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100,   100, 120, 70)];
    imageView.backgroundColor = [UIColor orangeColor];
    NSMutableArray *marr = [[NSMutableArray alloc] init];
    
    for (int i = 0; i < 12; i++) {
        NSString *string = [NSString stringWithFormat:@"img%d.png",i];
        UIImage *image = [UIImage imageNamed:string];
        [marr addObject:image];
    }
    imageView.animationImages = marr;
    imageView.animationDuration = 1;
    imageView.animationRepeatCount = 0;
    [imageView startAnimating];
    [self.view addSubview:imageView];

2、UIWebView加载gif

    CGRect frame = CGRectMake(100, 250, 0, 0);
    frame.size = [UIImage imageNamed:@"gundong.gif"].size;
    
    NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"gundong" ofType:@"gif"]];
    UIWebView *web = [[UIWebView alloc] initWithFrame:frame];
    web.userInteractionEnabled = NO;
    [web loadData:data MIMEType:@"image/gif" textEncodingName:@"" baseURL:[NSURL URLWithString:@""]];
    [self.view addSubview:web];

3、SDWebImage加载gif(4.0.0之前版本)

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 120, 70)];
    imageView.image = [UIImage sd_animatedGIFNamed:@"gundong"];
    [self.view addSubview:imageView];

4、FLAnimationImage加载gif(SDWebImage 4.0.0版本)

  • pod 'SDWebImage/GIF'即可导入FLAnimationImage
    4.0.0版本 UIImage+GIF.m 中也做了解释:


    UIImage+GIF.m

    意思就是:我们将只检索第一帧。完整的GIF支持可通过flanimatedimageview。

    CGRect frame = CGRectMake(100, 250, 0, 0);
    frame.size = [UIImage imageNamed:@"gundong.gif"].size;
    NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"gundong" ofType:@"gif"]];

    FLAnimatedImageView *flView = [[FLAnimatedImageView alloc] initWithFrame:CGRectMake(100, 400, frame.size.width, frame.size.height)];
    flView.animatedImage = [FLAnimatedImage animatedImageWithGIFData:data];
    flView.contentMode = UIViewContentModeScaleAspectFit;
    [self.view addSubview:flView];

[SDWebImage 加载显示 GIF 与性能问题](http://www.cnblogs.com/silence-cnblogs/p/6682867.html

相关文章

  • Swift (四) gif图片播放

    @[TOC](IOS gif图片播放 swift) 1. GIF在iOS平台上的几种加载方式 使用Dispatch...

  • iOS SDWebImage 加载GIF图片没效果

    //加载本地GIF图片 //加载网络GIF图片 (SDWebImage 4.0 之前) //加载网络GIF图片(S...

  • Android Glide 使用

    加载 GIF 图片到 ImageView 中 通常 Android 的 ImageView 不能加载 Gif 图片...

  • Xcode开发播放gif图片

    在开发iOS程序的过程中,可能会遇到要加载gif图片,下面介绍gif图片的加载方式:先介绍一个第三方:gifVie...

  • iOS Gif图片加载

    Gif图片如越来越受欢迎,移动端对它的支持也是有些知识点的,主要是加载图片性能优化 Gif图片的生成 Gif图片是...

  • iOS加载gif图片

    1、通过拆分gif,加载一个图片数组(推荐一个Mac APP自动拆分gif:Gif Preview) 2、UIWe...

  • iOS加载Gif图片

    Gif图片是非常常见的图片格式,尤其是在聊天的过程中,Gif表情使用地很频繁。但是iOS竟然没有现成的支持加载和播...

  • iOS 加载gif图片

    一,UIWebview加载 核心代码如下: 注意:上面的xib也就是,登录自定义view要在webview请求完之...

  • ios加载GIF图片

    原生的UIImageView是不支持gif格式图片的,以下是我总结的三种方法,希望可以帮助到你。 一、用UIWeb...

  • iOS加载Gif图片

    1.系统UIImageView 多张图片组成动画 2.利用第三方库 IImageView-PlayGIF YFGI...

网友评论

      本文标题:iOS加载gif图片

      本文链接:https://www.haomeiwen.com/subject/irklxxtx.html