kaishin / Gifu
- вторник, 29 марта 2016 г. в 03:11:45
Swift
High-performance animated GIF support for iOS in Swift
Adds performant animated GIF support to UIKit. If you're looking for the Japanese prefecture, click here.
Gifu uses a UIImageView
subclass and an animator that keeps track of frames and their durations.
It uses CADisplayLink
to animate the view and only keeps a limited number of
resized frames in-memory, which exponentially minimizes memory usage for large GIF files (+300 frames).
The figure below summarizes how this works in practice. Given an image containing 10 frames, Gifu will load the current frame (red), pre-load the next two frames in this example (orange), and nullify all the other frames to free up memory (gray):
github "kaishin/Gifu"
carthage update
pod 'Gifu'
use_frameworks!
pod install
with CocoaPods 0.36 or newer.Start by instantiating an AnimatableImageView
either in code or Interface Builder, then call animateWithImage(named:)
or animateWithImageData(data:)
on it.
let imageView = AnimatableImageView(frame: CGRect(...))
imageView.animateWithImage(named: "mugen.gif")
You can stop the animation anytime using imageView.stopAnimatingGIF()
, and resume
it using imageView.startAnimatingGIF()
.
The isAnimatingGIF()
method returns the current animation state of the view if it has an animatable image.
See the full documentation.
Clone or download the repository and open Gifu.xcworkspace
to check out the demo app.
See LICENSE.