让FLAnimatedImage支持SDWebImage的修改 -- Flipboard开源高性能动画GIF引擎(源码)

本文主要是介绍让FLAnimatedImage支持SDWebImage的修改 -- Flipboard开源高性能动画GIF引擎(源码),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

大家都已经知道,FLAnimatedImage是一个适用于iOS的高性能动画GIF引擎:
可同时播放多个GIF,回放速度可以和桌面浏览器匹敌,在压力内存下表现良好。FLAnimatedImage经过了良好的测试,实现了Flipboard中的GIF。

详细内容可参看:http://engineering.flipboard.com/2014/05/animated-gif/


源代码地址:https://github.com/Flipboard/FLAnimatedImage

FLAnimatedImage is a performant animated GIF engine for iOS:

  • Plays multiple GIFs simultaneously with a playback speed comparable to desktop browsers
  • Honors variable frame delays
  • Behaves gracefully under memory pressure
  • Eliminates delays or blocking during the first playback loop
  • Interprets the frame delays of fast GIFs the same way modern browsers do

It's a well-tested component that powers all GIFs in Flipboard. To understand its behavior it comes with an interactive demo:

Flipboard playing multiple GIFs

Who is this for?

  • Apps that don't support animated GIFs yet
  • Apps that already support animated GIFs but want a higher performance solution
  • People who want to tinker with the code (the corresponding blog post is a great place to start; also see the "To Do" section below)

Installation & Usage

FLAnimatedImage is a well encapsulated drop-in component. Simply replace your UIImageView instances with instances of FLAnimatedImageView to get animated GIF support. There is no central cache or state to manage.

To get started, simply copy the two classes FLAnimatedImage.h/.m and FLAnimatedImageView.h/.m into your Xcode project or add via CocoaPods by adding this to your Podfile:

pod 'FLAnimatedImage', '~> 1.0'

In your code, #import "FLAnimatedImage.h" and #import "FLAnimatedImageView.h" and then create an image from an animated GIF and setup the image view to display it:

FLAnimatedImage *image = [[FLAnimatedImage alloc] initWithAnimatedGIFData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://raphaelschaad.com/static/nyan.gif"]]];
FLAnimatedImageView *imageView = [[FLAnimatedImageView alloc] init];
imageView.animatedImage = image;
imageView.frame = CGRectMake(0.0, 0.0, 100.0, 100.0);
[self.view addSubview:imageView];

It's flexible to integrate in your custom image loading stack and backwards compatible to iOS 5.

It uses ARC and the Apple frameworks QuartzCoreImageIOMobileCoreServices, and CoreGraphics.

Since FLAnimatedImage is licensed under MIT it's compatible with the terms of using it for any app on the App Store.

To Do

  • Support other animated image formats such as APNG or WebP
  • Integration into network libraries and image caches
  • Investigate whether FLAnimatedImage should become a UIImage subclass
  • UIScrollView support
  • Smarter buffering
  • Bring demo app to iOS 5 and iPhone

This has shipped to many people and since mid 2013 we made many tweaks. But it's a version 1.0, so please come with your questions, issues and pull requests.

Feel free to reach out to @RaphaelSchaad for further help.



大家在运行demo时会卡顿很久,现在引入SDWebImage的cache机制,制作了一个category

此修改只适用于测试,不建议用在app中


源码地址:https://github.com/iunion/FLAnimatedImage


使用方法:

[objc]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. NSURL *url2 = [NSURL URLWithString:@"http://raphaelschaad.com/static/nyan.gif"];  
  2. //NSData *data2 = [NSData dataWithContentsOfURL:url2];  
  3. //FLAnimatedImage *animatedImage2 = [[FLAnimatedImage alloc] initWithAnimatedGIFData:data2];  
  4. //self.imageView2.animatedImage = animatedImage2;  
  5. __block RootViewController *aself = self;  
  6. [self.imageView2 setImageWithURL:url2 animatedsuccess:^(UIImage *image, FLAnimatedImage *animatedImage, BOOL cached) {  
  7.     aself.imageView2.debug_delegate = aself.debugView2;  
  8.     animatedImage.debug_delegate = aself.debugView2;  
  9.     aself.debugView2.imageView = aself.imageView2;  
  10.     aself.debugView2.image = animatedImage;  
  11.     aself.imageView2.userInteractionEnabled = YES;  
  12. } failure:^(NSError *error) {  
  13.   
  14. }];  让FLAnimatedImage支持SDWebImage的修改 -- Flipboard开源高性能动画GIF引擎(源码)

这篇关于让FLAnimatedImage支持SDWebImage的修改 -- Flipboard开源高性能动画GIF引擎(源码)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/349979

相关文章

python实现svg图片转换为png和gif

《python实现svg图片转换为png和gif》这篇文章主要为大家详细介绍了python如何实现将svg图片格式转换为png和gif,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录python实现svg图片转换为png和gifpython实现图片格式之间的相互转换延展:基于Py

Java 正则表达式URL 匹配与源码全解析

《Java正则表达式URL匹配与源码全解析》在Web应用开发中,我们经常需要对URL进行格式验证,今天我们结合Java的Pattern和Matcher类,深入理解正则表达式在实际应用中... 目录1.正则表达式分解:2. 添加域名匹配 (2)3. 添加路径和查询参数匹配 (3) 4. 最终优化版本5.设计思

Java调用C++动态库超详细步骤讲解(附源码)

《Java调用C++动态库超详细步骤讲解(附源码)》C语言因其高效和接近硬件的特性,时常会被用在性能要求较高或者需要直接操作硬件的场合,:本文主要介绍Java调用C++动态库的相关资料,文中通过代... 目录一、直接调用C++库第一步:动态库生成(vs2017+qt5.12.10)第二步:Java调用C++

Docker镜像修改hosts及dockerfile修改hosts文件的实现方式

《Docker镜像修改hosts及dockerfile修改hosts文件的实现方式》:本文主要介绍Docker镜像修改hosts及dockerfile修改hosts文件的实现方式,具有很好的参考价... 目录docker镜像修改hosts及dockerfile修改hosts文件准备 dockerfile 文

SpringKafka消息发布之KafkaTemplate与事务支持功能

《SpringKafka消息发布之KafkaTemplate与事务支持功能》通过本文介绍的基本用法、序列化选项、事务支持、错误处理和性能优化技术,开发者可以构建高效可靠的Kafka消息发布系统,事务支... 目录引言一、KafkaTemplate基础二、消息序列化三、事务支持机制四、错误处理与重试五、性能优

Python实现无痛修改第三方库源码的方法详解

《Python实现无痛修改第三方库源码的方法详解》很多时候,我们下载的第三方库是不会有需求不满足的情况,但也有极少的情况,第三方库没有兼顾到需求,本文将介绍几个修改源码的操作,大家可以根据需求进行选择... 目录需求不符合模拟示例 1. 修改源文件2. 继承修改3. 猴子补丁4. 追踪局部变量需求不符合很

Linux修改pip和conda缓存路径的几种方法

《Linux修改pip和conda缓存路径的几种方法》在Python生态中,pip和conda是两种常见的软件包管理工具,它们在安装、更新和卸载软件包时都会使用缓存来提高效率,适当地修改它们的缓存路径... 目录一、pip 和 conda 的缓存机制1. pip 的缓存机制默认缓存路径2. conda 的缓

Linux修改pip临时目录方法的详解

《Linux修改pip临时目录方法的详解》在Linux系统中,pip在安装Python包时会使用临时目录(TMPDIR),但默认的临时目录可能会受到存储空间不足或权限问题的影响,所以本文将详细介绍如何... 目录引言一、为什么要修改 pip 的临时目录?1. 解决存储空间不足的问题2. 解决权限问题3. 提

Linux文件名修改方法大全

《Linux文件名修改方法大全》在Linux系统中,文件名修改是一个常见且重要的操作,文件名修改可以更好地管理文件和文件夹,使其更具可读性和有序性,本文将介绍三种在Linux系统下常用的文件名修改方法... 目录一、引言二、使用mv命令修改文件名三、使用rename命令修改文件名四、mv命令和rename命

Spring 中 BeanFactoryPostProcessor 的作用和示例源码分析

《Spring中BeanFactoryPostProcessor的作用和示例源码分析》Spring的BeanFactoryPostProcessor是容器初始化的扩展接口,允许在Bean实例化前... 目录一、概览1. 核心定位2. 核心功能详解3. 关键特性二、Spring 内置的 BeanFactory