1.系统UIImageView 多张图片组成动画

/**
* UIImageView 动画
* Memory-23M
*/
-(void)gifPlay1
{
// NSArray *array=@[@"image0.png",@"image1.png",@"image2.png"];
// UIImageView *imgview= [UIImageView imageViewAnimation:CGRectMake(50,80, 550/2, 200) imageNames:array duration:1]; UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(50,80, 550/2, 200)];
animatedImageView.animationImages =@[[UIImage imageNamed:@"image0"],
[UIImage imageNamed:@"image1"],
[UIImage imageNamed:@"image2"],
];
animatedImageView.animationDuration = 1.0f;
animatedImageView.animationRepeatCount = 0;
[self.view addSubview: animatedImageView];
[animatedImageView startAnimating];
}

2.利用第三方库

1)IImageView-PlayGIF  YFGIFImageView

/**
* UIImageView-PlayGIF 是 UIImageView 子类,用来显示 GIF。UIIMageView-PlayGIF 性能高,而且占用的内存很低。
* https://github.com/yfme/UIImageView-PlayGIF
* Memory-21.9M
* #import "YFGIFImageView.h"
*/
-(void)gifPlay2
{
NSString *gifPath=[[NSBundle mainBundle] pathForResource:@"test" ofType:@"gif"];
YFGIFImageView *gifview=[[YFGIFImageView alloc]init];
gifview.backgroundColor=[UIColor clearColor];
gifview.gifPath=gifPath;
gifview.frame=CGRectMake(50, 100,550/2, 200);
[self.view addSubview:gifview];
[gifview startGIF];
}

2)SCGIFImageView

/**
* 摘要: SCGIFImageView是一个开源的GIF图片动画显示控件,通过将GIF的每一帧都取出来生成UIImage对象存放在一个数组中,然后使用NSTimer进行动画轮转。
* https://github.com/shichangone/SCGifExample
* Memory-22.5M
* #import "SCGIFImageView.h"
*/
-(void)gifPlay3
{
NSString* filePath = [[NSBundle mainBundle] pathForResource:@"test.gif" ofType:nil];
NSData* imageData = [NSData dataWithContentsOfFile:filePath];
SCGIFImageView* gifImageView = [[SCGIFImageView alloc]init];
[gifImageView setData:imageData];
gifImageView.frame = CGRectMake(50,100, gifImageView.image.size.width, gifImageView.image.size.height);
[self.view addSubview:gifImageView];
}

3)YLGIFImage

/**
* YLGIFImage 是异步 GIF 图像解码器和图像查看器,支持播放 GIF 图像,而且使用很少的内存。
* https://github.com/liyong03/YLGIFImage
* Memory-22.7M
* #import "YLImageView.h"
* #import "YLGIFImage.h"
*/
-(void)gifPlay5
{
YLImageView* imageView = [[YLImageView alloc] initWithFrame:CGRectMake(0, 160, 320, 240)];
[self.view addSubview:imageView];
imageView.image = [YLGIFImage imageNamed:@"test.gif"];
}

4)SDWebImageView里的UIImage+GIF

提供接口:

+ (UIImage *)sd_animatedGIFNamed:(NSString *)name;
+ (UIImage *)sd_animatedGIFWithData:(NSData *)data;
- (UIImage *)sd_animatedImageByScalingAndCroppingToSize:(CGSize)size;

/**
* 利用SDWebImageView 库播放gif
* Memory-22.6M
* #import "UIImage+GIF.h"
*/
-(void)gifPlay6
{
UIImage *image=[UIImage sd_animatedGIFNamed:@"test"];
UIImageView *gifview=[[UIImageView alloc]initWithFrame:CGRectMake(50,80,image.size.width, image.size.height)];
gifview.backgroundColor=[UIColor orangeColor];
gifview.image=image;
[self.view addSubview:gifview];
}

为MBProgressHUD 添加加载动画

/**
* MBProgressHUD 添加加载动画
* Memory-23.8M
* #import "UIImage+GIF.h"
* #import "MBProgressHUD.h"
*/
-(void)gifPlay6
{
UIImage *image=[UIImage sd_animatedGIFNamed:@"test"];
UIImageView *gifview=[[UIImageView alloc]initWithFrame:CGRectMake(0,0,image.size.width/2, image.size.height/2)];
gifview.image=image; MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.color=[UIColor grayColor];//默认颜色太深了
hud.mode = MBProgressHUDModeCustomView;
hud.labelText = @"加载中...";
hud.customView=gifview;
}

其它

微博客户端 VVebo 的作者开源了他自己为VVebo写的GIF解决方案 VVeboImageView, 占用内存很小。(iOS移动开发周报-第4期)

 
Demo下载
http://yunpan.cn/cj6JBN7mfETWE (提取码:226f)
 
 
 
 
 
 
 

iOS加载Gif图片的N种方式 By-H罗的更多相关文章

  1. qt加载背景图片的一种方式

    //加载背景图片 void LCTGrid::loadBgPicture() { QImage image; QPalette palette; image.load(m_sPicturePath); ...

  2. UIImage加载本地图片的两种方式

    UIImage加载图片方式一般有两种: (1)imagedNamed初始化:默认加载图片成功后会内存中缓存图片,这个方法用一个指定的名字在系统缓存中查找并返回一个图片对象.如果缓存中没有找到相应的图片 ...

  3. Unity加载本地图片的2种方式

    1. 使用 WWW 加载,详细查看 unity3d 官方文档. 2. 使用 System.IO 加载,lua 代码如下: local File = luanet.import_type("S ...

  4. ios网络学习------4 UIWebView的加载本地数据的三种方式

    ios网络学习------4 UIWebView的加载本地数据的三种方式 分类: IOS2014-06-27 12:56 959人阅读 评论(0) 收藏 举报 UIWebView是IOS内置的浏览器, ...

  5. 加载xib文件的两种方式

    一.加载xib文件的两种方式 1.方法一(NewsCell是xib文件的名称) NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@&quo ...

  6. 转 Velocity中加载vm文件的三种方式

    Velocity中加载vm文件的三种方式   velocitypropertiespath Velocity中加载vm文件的三种方式:    方式一:加载classpath目录下的vm文件 Prope ...

  7. Spring加载properties文件的两种方式

    在项目中如果有些参数经常需要修改,或者后期可能需要修改,那我们最好把这些参数放到properties文件中,源代码中读取properties里面的配置,这样后期只需要改动properties文件即可, ...

  8. Hadoop生态圈-注册并加载协处理器(coprocessor)的三种方式

    Hadoop生态圈-注册并加载协处理器(coprocessor)的三种方式 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 到目前为止,大家已经掌握了如何使用过滤器来减少服务器端通过 ...

  9. Velocity中加载vm文件的三种方式

    Velocity中加载vm文件的三种方式: a.  加载classpath目录下的vm文件 /** * 初始化Velocity引擎 * --VelocityEngine是单例模式,线程安全 * @th ...

随机推荐

  1. shc命令

    今天在公司看到业务系统有一个query.viewtx 等等命令.虽然不知道是什么语言写的,但是里边内容是看不到的. 如果是编译型语言这样的结果 我并不奇怪.但是如果我们写了一个shell脚本 如果加密 ...

  2. centos6.5-nginx搭建

    一.安装nginx 1.安装相关组件 yum -y install pcre-devel zlib-devel 2.创建启动用户 useradd -M -s /sbin/nologin nginx t ...

  3. mysql语句3-插入、修改删除表

    二.DML数据操纵语句 关键字:insert(插入)  delete(删除)  update(更新)  select(查询) 1.表创建好以后,就可以插入记录了,语法如下: 方法一 :insert i ...

  4. CSS基础 列表相关的属性的使用

    1.无序列表:就是不需要排列顺序的情况,用无序列表 语法结构:<ul> <li></li> <li></li> </ul> 特点 ...

  5. store在模块化后,获取state中的值时undefined

    目录结构 用this.$store.getters.showNotif ,加上模块名this.$store.getters.apply.showNotif都取不到值, 控制台打印store,发现这样的 ...

  6. STC8H开发(四): FwLib_STC8 封装库的介绍和注意事项

    目录 STC8H开发(一): 在Keil5中配置和使用FwLib_STC8封装库(图文详解) STC8H开发(二): 在Linux VSCode中配置和使用FwLib_STC8封装库(图文详解) ST ...

  7. 《Go组件设计与实现》-netpoll的总结

    主要针对字节跳动的netpoll网络库进行总结.netpoll网络库相比于go本身的net标准库更适合高并发场景. 基础知识 netpoll与go.net库一样使用epoll这种IO多路复用机制处理网 ...

  8. UDP代码编写、操作系统发展史、多道技术、进程理论与代码层面创建、进程join方法与进程对象方法

    昨日内容回顾 socket基本使用 # 内置的模块 import socket s = socket.socket() # 默认是TCP协议 也可以切换为UDP协议 s.bind((ip,port)) ...

  9. js中数字和字母互转的方法

    var letter = String.fromCharCode(66); // B var num = "B".charCodeAt(); // 66

  10. Ubuntu16桌面版编译和安装OpenCV4

    欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...