<p><ahref="https://github.com/kaishin/Gifu/releases/latest"><imgsrc="https://img.shields.io/github/release/kaishin/Gifu.svg?maxAge=2592000"alt="GitHub release"></a><ahref="https://travis-ci.org/kaishin/Gifu"><imgsrc="https://travis-ci.org/kaishin/Gifu.svg?branch=master"alt="Travis"></a><ahref="https://github.com/Carthage/Carthage"><imgsrc="https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat"alt="Carthage compatible"></a><ahref="https://gitter.im/kaishin/gifu"><imgsrc="https://badges.gitter.im/kaishin/gifu.svg"alt="Join the chat at https://gitter.im/kaishin/gifu"></a><imgsrc="https://img.shields.io/badge/Swift-3.0.x-orange.svg"alt="Swift 3.0.x"><imgsrc="https://img.shields.io/badge/platforms-iOS-lightgrey.svg"alt="platforms"></p>
<p>Gifu adds protocol-based, performance-aware animated GIF support to UIKit. (It’s also a <ahref="https://goo.gl/maps/CCeAc">prefecture in Japan</a>).</p>
<p>⚠ <strong>Swift 2.3</strong> support is on the <ahref="https://github.com/kaishin/Gifu/tree/swift2.3">swift2.3</a> branch. <strong>This branch will not be getting any future updates</strong>.</p>
<p><code>Gifu</code> does not force you to use a specific subclass of <code>UIImageView</code>. The <code>Animator</code> class does the heavy-lifting, while the <code>GIFAnimatable</code> protocol exposes the functionality to the view classes that conform to it, using protocol extensions.</p>
<p>The <code>Animator</code> has a <code>FrameStore</code> that only keeps a limited number of frames in-memory, effectively creating a buffer for the animation without consuming all the available memory. This approach makes loading large GIFs a lot more resource-friendly.</p>
<p>The figure below summarizes how this works in practice. Given an image
containing 10 frames, Gifu will load the current frame (red), buffer the next two frames in this example (orange), and empty up all the other frames to free up memory (gray):</p>
<li>Make any class conform to <code>GIFAnimatable</code>. Subclassing <code>UIImageView</code> is the easiest since you get most of the required properties for free.</li>
<p>A subclass of <code>UIImageView</code> that conforms to <code>GIFAnimatable</code>. You can use this class as-is or subclass it for further customization (not recommended).</p>
<p>The bread and butter of Gifu. Through protocol extensions, <code>GIFAnimatable</code> exposes all the APIs of the library, and with very little boilerplate, any <code>UIImageView</code> subclass can conform to it.</p>
<p>That’s it. Now <code>MyImageView</code> is fully GIF-compatible, and any of these methods can be called on it:</p>
<ul>
<li><code>prepareForAnimation(withGIFNamed:)</code> and <code>prepareForAnimation(withGIFData:)</code> to prepare the animator property for animation.</li>
<li><code>startAnimatingGIF()</code> and <code>stopAnimatingGIF()</code> to control the animation.</li>
<li><code>animate(withGIFNamed:)</code> and <code>animate(withGIFData:)</code> to prepare for animation and start animating immediately.</li>
<li><code>frameCount</code>, <code>isAnimatingGIF</code>, and <code>activeFrame</code> to inspect the GIF view.</li>
<li><code>prepareForReuse()</code> to free up resources.</li>
<li><code>updateImageIfNeeded()</code> to update the image property if necessary.</li>
<p>Keep in mind that you need to have control over the class implementing <code>GIFAnimatable</code> since you cannot add the stored <code>Animator</code> property in an extension.</p>
<p>The simplest way to get started is initializing a <code>GIFAnimatable</code> class in code or in a storyboard, then calling <code>animate(:)</code> on it.</p>
<p>If you are using a <code>GIFAnimatable</code> class in a table or collection view, you can call the <code>prepareForReuse()</code> method in your cell subclass:</p>
<p>Generated by <aclass="link"href="https://github.com/realm/jazzy"target="_blank"rel="external">jazzy ♪♫ v0.7.2</a>, a <aclass="link"href="http://realm.io"target="_blank"rel="external">Realm</a> project.</p>