iOS 的 Gif 渲染引擎 FLAnimatedImage

公司的项目有个首页加载一张2M左右的git图,刚做的时候是使用的SDWebImage里面的方法:

+ (UIImage *)sd_animatedGIFNamed:(NSString *)name;
+ (UIImage *)sd_animatedGIFWithData:(NSData *)data;

​使用之后发现这个方法会使内存迅速上增300M,在网上找了一些方法:

//在didReceiveMemoryWarning方法中释放SDImage的缓存即可!
- (void)didReceiveMemoryWarning {
       [superdidReceiveMemoryWarning];
        // Dispose of     any resources that can be recreated.
       [[SDWebImageManagersharedManager]cancelAll];
       [[SDImageCachesharedImageCache]clearDisk];
}

​但是使用之后发现效果并不明显,于是使用了这个FLAnimatedImage,瞬间没存回到原来的位置.

FLAnimatedImage 是 iOS 的一个渲染 Gif 动画的引擎。

1.可同时播放多个 Gif
2.动画,速度媲美桌面浏览器
3.可变帧延迟
4.内存占用小
5.可在第一次循环播放时消除或者阻止延迟
6.动画的帧延迟解析性能媲美浏览器

示例代码:

FLAnimatedImage *image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"https://upload.wikimedia.org/wikipedia/commons/2/2c/Rotating_earth_%28large%29.gif"]]];
FLAnimatedImageView *imageView = [[FLAnimatedImageView alloc] init];
imageView.animatedImage = image;
imageView.frame = CGRectMake(0.0, 0.0, 100.0, 100.0);
[self.view addSubview:imageView];

效果图:

iOS 的 Gif 渲染引擎 FLAnimatedImage_第1张图片

github地址:https://github.com/Flipboard/FLAnimatedImage 



长按关注:

iOS 的 Gif 渲染引擎 FLAnimatedImage_第2张图片

QQ群:427763454

欢迎你的投稿,展示的你的技术文章:[email protected]

你可能感兴趣的:(iOS 的 Gif 渲染引擎 FLAnimatedImage)