FLAnimatedImage

Performant animated GIF engine for iOS

  • 所有者: Flipboard/FLAnimatedImage
  • 平台:
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

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.

If using CocoaPods, the quickest way to try it out is to type this on the command line:

$ pod try FLAnimatedImage

To add it to your app, 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'

If using Carthage, add the following line into your Cartfile

github "Flipboard/FLAnimatedImage"

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

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];

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

It uses ARC and the Apple frameworks QuartzCore, ImageIO, MobileCoreServices, and CoreGraphics.

It is capable of fine-grained logging. A block can be set on FLAnimatedImage that's invoked when logging occurs with various log levels via the +setLogBlock:logLevel: method. For example:

// Set up FLAnimatedImage logging.
[FLAnimatedImage setLogBlock:^(NSString *logString, FLLogLevel logLevel) {
    // Using NSLog
    NSLog(@"%@", logString);
    
    // ...or CocoaLumberjackLogger only logging warnings and errors
    if (logLevel == FLLogLevelError) {
        DDLogError(@"%@", logString);
    } else if (logLevel == FLLogLevelWarn) {
        DDLogWarn(@"%@", logString);
    }
} logLevel:FLLogLevelWarn];

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 (WebP support implemented here)
  • Integration into network libraries and image caches
  • Investigate whether FLAnimatedImage should become a UIImage subclass
  • Smarter buffering
  • Bring demo app to iPhone

This code has successfully shipped to many people as is, but please do come with your questions, issues and pull requests!

Select apps using FLAnimatedImage

(alphabetically)

If you're using FLAnimatedImage in your app, please open a PR to add it to this list!

主要指標

概覽
名稱與所有者Flipboard/FLAnimatedImage
主編程語言Objective-C
編程語言Ruby (語言數: 3)
平台
許可證MIT License
所有者活动
創建於2014-05-19 17:44:51
推送於2024-03-21 10:45:04
最后一次提交2022-07-27 15:55:13
發布數18
最新版本名稱1.0.17 (發布於 )
第一版名稱1.0.0 (發布於 2014-05-29 07:06:33)
用户参与
星數8k
關注者數223
派生數1.2k
提交數276
已啟用問題?
問題數160
打開的問題數76
拉請求數50
打開的拉請求數8
關閉的拉請求數56
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?