You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
4.5 KiB

  1. FLAnimatedImage is a performant animated GIF engine for iOS:
  2. - Plays multiple GIFs simultaneously with a playback speed comparable to desktop browsers
  3. - Honors variable frame delays
  4. - Behaves gracefully under memory pressure
  5. - Eliminates delays or blocking during the first playback loop
  6. - Interprets the frame delays of fast GIFs the same way modern browsers do
  7. It's a well-tested [component that powers all GIFs in Flipboard](http://engineering.flipboard.com/2014/05/animated-gif/). To understand its behavior it comes with an interactive demo:
  8. ![Flipboard playing multiple GIFs](https://github.com/Flipboard/FLAnimatedImage/raw/master/images/flanimatedimage-demo-player.gif)
  9. ## Who is this for?
  10. - Apps that don't support animated GIFs yet
  11. - Apps that already support animated GIFs but want a higher performance solution
  12. - People who want to tinker with the code ([the corresponding blog post](http://engineering.flipboard.com/2014/05/animated-gif/) is a great place to start; also see the *To Do* section below)
  13. ## Installation & Usage
  14. 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.
  15. If using CocoaPods, the quickest way to try it out is to type this on the command line:
  16. ```shell
  17. $ pod try FLAnimatedImage
  18. ```
  19. 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](http://cocoapods.org) by adding this to your Podfile:
  20. ```ruby
  21. pod 'FLAnimatedImage', '~> 1.0'
  22. ```
  23. If using [Carthage](https://github.com/Carthage/Carthage), add following line into your `Cartfile`
  24. ```
  25. github "Flipboard/FLAnimatedImage"
  26. ```
  27. In your code, `#import "FLAnimatedImage.h"`, create an image from an animated GIF, and setup the image view to display it:
  28. ```objective-c
  29. FLAnimatedImage *image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"https://upload.wikimedia.org/wikipedia/commons/2/2c/Rotating_earth_%28large%29.gif"]]];
  30. FLAnimatedImageView *imageView = [[FLAnimatedImageView alloc] init];
  31. imageView.animatedImage = image;
  32. imageView.frame = CGRectMake(0.0, 0.0, 100.0, 100.0);
  33. [self.view addSubview:imageView];
  34. ```
  35. It's flexible to integrate in your custom image loading stack and backwards compatible to iOS 6.
  36. It uses ARC and the Apple frameworks `QuartzCore`, `ImageIO`, `MobileCoreServices`, and `CoreGraphics`.
  37. 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:
  38. ```objective-c
  39. // Set up FLAnimatedImage logging.
  40. [FLAnimatedImage setLogBlock:^(NSString *logString, FLLogLevel logLevel) {
  41. // Using NSLog
  42. NSLog(@"%@", logString);
  43. // ...or CocoaLumberjackLogger only logging warnings and errors
  44. if (logLevel == FLLogLevelError) {
  45. DDLogError(@"%@", logString);
  46. } else if (logLevel == FLLogLevelWarn) {
  47. DDLogWarn(@"%@", logString);
  48. }
  49. } logLevel:FLLogLevelWarn];
  50. ```
  51. Since FLAnimatedImage is licensed under MIT, it's compatible with the terms of using it for any app on the App Store.
  52. ## To Do
  53. - Support other animated image formats such as APNG or WebP (WebP support implemented [here](https://github.com/Flipboard/FLAnimatedImage/pull/86))
  54. - Integration into network libraries and image caches
  55. - Investigate whether `FLAnimatedImage` should become a `UIImage` subclass
  56. - Smarter buffering
  57. - Bring demo app to iPhone
  58. This has successfully shipped to many people as is, but please do come with your questions, issues and pull requests!
  59. ## Select apps using FLAnimatedImage
  60. - [Dropbox](https://www.dropbox.com)
  61. - [Medium](https://medium.com)
  62. - [Facebook](https://facebook.com)
  63. - [Pinterest](https://pinterest.com)
  64. - [LiveBooth](http://www.liveboothapp.com)
  65. - [Design Shots](https://itunes.apple.com/app/id792517951)
  66. - [lWlVl Festival](http://lwlvl.com)
  67. - [Close-up](http://closeu.pe)
  68. - [Zip Code Finder](https://itunes.apple.com/app/id893031254)
  69. - [getGIF](https://itunes.apple.com/app/id964784701)
  70. - [Giffage](http://giffage.com)
  71. - [Flipboard](https://flipboard.com)
  72. - [Gifalicious](https://itunes.apple.com/us/app/gifalicious-see-your-gifs/id965346708?mt=8)
  73. - [Slack](https://slack.com/)
  74. - [Telegram](https://telegram.org/)
  75. - [HashPhotos](https://itunes.apple.com/app/id685784609)
  76. - [Ello](https://ello.co/)
  77. - [Dumpert](http://dumpert.nl)
  78. If you're using FLAnimatedImage in your app please open a PR to add it to this list!