让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引擎(源码)
展开阅读全文

没有更多推荐了,返回首页