iOS開源:FLAnimatedImage - iOS 的 Gif 渲染引擎

ghte5147 7年前發布 | 10K 次閱讀 iOS開發 移動開發

公司的項目有個首頁加載一張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];

?

效果圖:

 

來自:http://www.jianshu.com/p/3e41f354c423

 

 本文由用戶 ghte5147 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!