• SDWebImage播放GIF图


    播放GIF图有好几种方法

    1.可以直接用ImageView一帧一帧的播放

    2.可以用WebView加载一个页面播放

    .

    .

    .

    但是它们的缺点比较明显,会失帧,如果图比较大多话,还有可能在屏幕比较小的设备上不能完全显示出来,

    SDWebImage提供了很好的方法,只要导入播放GIF的头文件,只需短短的几行代码就可以实现。示例代码如下:

    #import "ViewController.h"
    #import "UIImage+GIF.h"
    @interface ViewController ()
    @property (nonatomic,strong) UIImageView *loadingImageView;
    @end

    @implementation ViewController

    - (void)viewDidLoad {
        [super viewDidLoad];
        [self initLoadingImageView];
    }

    - (void)initLoadingImageView
    {
     
        NSString  *name = @"4升级.gif";
        NSString  *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]] pathForResource:name ofType:nil];
        NSData  *imageData = [NSData dataWithContentsOfFile:filePath];
        
      if (!self.loadingImageView) {    
            self.loadingImageView = [[UIImageView alloc]init];
        }
        self.loadingImageView.backgroundColor = [UIColor clearColor];
        
        self.loadingImageView.image = [UIImage sd_animatedGIFWithData:imageData];
        self.loadingImageView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
        
        [self.view addSubview:self.loadingImageView];
        
        [self.view bringSubviewToFront:self.loadingImageView];
        
    }
    @end

  • 相关阅读:
    matplot 代码实例2
    sklearn 线性模型使用入门
    python 之 决策树分类算法
    Leetcode 之Simplify Path @ python
    协同过滤CF算法之入门
    linux 下 rpc python 实例之使用XML-RPC进行远程文件共享
    Linux rpc 编程最简单实例
    Opencv 入门学习之图片人脸识别
    Django1.7开发博客
    Opencv 入门学习1
  • 原文地址:https://www.cnblogs.com/MJP334414/p/4953922.html
Copyright © 2020-2023  润新知