Drop image property requirement

This commit is contained in:
Reda Lemeden 2016-10-08 19:36:32 +02:00
parent a3617f77bc
commit 0fe1fc5cec
21 changed files with 388 additions and 74 deletions

View File

@ -4,12 +4,28 @@ import Gifu
class EmptyViewController: UIViewController { class EmptyViewController: UIViewController {
let imageView = GIFImageView(image: #imageLiteral(resourceName: "mugen.gif")) let imageView = GIFImageView(image: #imageLiteral(resourceName: "mugen.gif"))
lazy var customImageView: CustomAnimatedView = {
return CustomAnimatedView(frame: CGRect(x: 0, y: self.view.frame.height - 200, width: 360, height: 200))
}()
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
view.addSubview(imageView) view.addSubview(imageView)
view.addSubview(customImageView)
} }
override func viewDidAppear(_ animated: Bool) { override func viewDidAppear(_ animated: Bool) {
imageView.animate(withGIFNamed: "mugen") imageView.animate(withGIFNamed: "mugen")
customImageView.animate(withGIFNamed: "earth")
}
}
class CustomAnimatedView: UIView, GIFAnimatable {
public lazy var animator: Animator? = {
return Animator(withDelegate: self)
}()
override public func display(_ layer: CALayer) {
updateImageIfNeeded()
} }
} }

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="16A323" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="16A323" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="E4d-Zb-hdl">
<dependencies> <dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/> <capability name="Aspect ratio constraints" minToolsVersion="5.1"/>

View File

@ -19,6 +19,7 @@
00B8C75F1A364DCE00C188E7 /* ImageSourceHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00B8C75C1A364DCE00C188E7 /* ImageSourceHelpers.swift */; }; 00B8C75F1A364DCE00C188E7 /* ImageSourceHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00B8C75C1A364DCE00C188E7 /* ImageSourceHelpers.swift */; };
00B8C7961A3650EE00C188E7 /* Gifu.h in Headers */ = {isa = PBXBuildFile; fileRef = 00B8C7951A3650EE00C188E7 /* Gifu.h */; settings = {ATTRIBUTES = (Public, ); }; }; 00B8C7961A3650EE00C188E7 /* Gifu.h in Headers */ = {isa = PBXBuildFile; fileRef = 00B8C7951A3650EE00C188E7 /* Gifu.h */; settings = {ATTRIBUTES = (Public, ); }; };
00BF42CC1D99A1DC00C6F28D /* GIFAnimatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00BF42CB1D99A1DC00C6F28D /* GIFAnimatable.swift */; }; 00BF42CC1D99A1DC00C6F28D /* GIFAnimatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00BF42CB1D99A1DC00C6F28D /* GIFAnimatable.swift */; };
00DD26EE1DA9643800A0F683 /* UIImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00DD26ED1DA9643800A0F683 /* UIImageView.swift */; };
EAF49C7F1A3A4DE000B395DF /* UIImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF49C7E1A3A4DE000B395DF /* UIImage.swift */; }; EAF49C7F1A3A4DE000B395DF /* UIImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF49C7E1A3A4DE000B395DF /* UIImage.swift */; };
EAF49CB11A3B6EEB00B395DF /* AnimatedFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF49CB01A3B6EEB00B395DF /* AnimatedFrame.swift */; }; EAF49CB11A3B6EEB00B395DF /* AnimatedFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF49CB01A3B6EEB00B395DF /* AnimatedFrame.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
@ -49,6 +50,7 @@
00B8C75C1A364DCE00C188E7 /* ImageSourceHelpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageSourceHelpers.swift; sourceTree = "<group>"; }; 00B8C75C1A364DCE00C188E7 /* ImageSourceHelpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageSourceHelpers.swift; sourceTree = "<group>"; };
00B8C7951A3650EE00C188E7 /* Gifu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Gifu.h; sourceTree = "<group>"; }; 00B8C7951A3650EE00C188E7 /* Gifu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Gifu.h; sourceTree = "<group>"; };
00BF42CB1D99A1DC00C6F28D /* GIFAnimatable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GIFAnimatable.swift; sourceTree = "<group>"; }; 00BF42CB1D99A1DC00C6F28D /* GIFAnimatable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GIFAnimatable.swift; sourceTree = "<group>"; };
00DD26ED1DA9643800A0F683 /* UIImageView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIImageView.swift; sourceTree = "<group>"; };
EAF49C7E1A3A4DE000B395DF /* UIImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIImage.swift; sourceTree = "<group>"; }; EAF49C7E1A3A4DE000B395DF /* UIImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIImage.swift; sourceTree = "<group>"; };
EAF49CB01A3B6EEB00B395DF /* AnimatedFrame.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnimatedFrame.swift; sourceTree = "<group>"; }; EAF49CB01A3B6EEB00B395DF /* AnimatedFrame.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnimatedFrame.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
@ -87,6 +89,7 @@
007E08431BD95E6200883D0C /* Array.swift */, 007E08431BD95E6200883D0C /* Array.swift */,
009BD1431BBC93C800FC982B /* CGSize.swift */, 009BD1431BBC93C800FC982B /* CGSize.swift */,
EAF49C7E1A3A4DE000B395DF /* UIImage.swift */, EAF49C7E1A3A4DE000B395DF /* UIImage.swift */,
00DD26ED1DA9643800A0F683 /* UIImageView.swift */,
); );
path = Extensions; path = Extensions;
sourceTree = "<group>"; sourceTree = "<group>";
@ -304,6 +307,7 @@
009BD1441BBC93C800FC982B /* CGSize.swift in Sources */, 009BD1441BBC93C800FC982B /* CGSize.swift in Sources */,
EAF49CB11A3B6EEB00B395DF /* AnimatedFrame.swift in Sources */, EAF49CB11A3B6EEB00B395DF /* AnimatedFrame.swift in Sources */,
00B8C75F1A364DCE00C188E7 /* ImageSourceHelpers.swift in Sources */, 00B8C75F1A364DCE00C188E7 /* ImageSourceHelpers.swift in Sources */,
00DD26EE1DA9643800A0F683 /* UIImageView.swift in Sources */,
00978B6C1D9C6D2A00A6575F /* Animator.swift in Sources */, 00978B6C1D9C6D2A00A6575F /* Animator.swift in Sources */,
007E08441BD95E6200883D0C /* Array.swift in Sources */, 007E08441BD95E6200883D0C /* Array.swift in Sources */,
EAF49C7F1A3A4DE000B395DF /* UIImage.swift in Sources */, EAF49C7F1A3A4DE000B395DF /* UIImage.swift in Sources */,

View File

@ -4,9 +4,6 @@ public protocol GIFAnimatable: class {
/// Responsible for managing the animation frames. /// Responsible for managing the animation frames.
var animator: Animator? { get set } var animator: Animator? { get set }
/// Used for displaying the animation frames.
var image: UIImage? { get set }
/// Notifies the instance that it needs display. /// Notifies the instance that it needs display.
var layer: CALayer { get } var layer: CALayer { get }
@ -17,12 +14,21 @@ public protocol GIFAnimatable: class {
var contentMode: UIViewContentMode { get set } var contentMode: UIViewContentMode { get set }
} }
extension GIFAnimatable {
/// A single-property protocol that animatable classes can optionally conform to.
public protocol ImageContainer {
/// Used for displaying the animation frames.
var image: UIImage? { get set }
}
extension GIFAnimatable where Self: ImageContainer {
/// Returns the intrinsic content size based on the size of the image. /// Returns the intrinsic content size based on the size of the image.
public var intrinsicContentSize: CGSize { public var intrinsicContentSize: CGSize {
return image?.size ?? CGSize.zero return image?.size ?? CGSize.zero
} }
}
extension GIFAnimatable {
/// Returns the active frame if available. /// Returns the active frame if available.
public var activeFrame: UIImage? { public var activeFrame: UIImage? {
return animator?.activeFrame() return animator?.activeFrame()
@ -63,7 +69,10 @@ extension GIFAnimatable {
/// ///
/// - parameter imageData: GIF image data. /// - parameter imageData: GIF image data.
public func prepareForAnimation(withGIFData imageData: Data) { public func prepareForAnimation(withGIFData imageData: Data) {
image = UIImage(data: imageData) if var imageContainer = self as? ImageContainer {
imageContainer.image = UIImage(data: imageData)
}
animator?.prepareForAnimation(withGIFData: imageData, size: frame.size, contentMode: contentMode) animator?.prepareForAnimation(withGIFData: imageData, size: frame.size, contentMode: contentMode)
} }
@ -85,8 +94,11 @@ extension GIFAnimatable {
/// Updates the image with a new frame if necessary. /// Updates the image with a new frame if necessary.
public func updateImageIfNeeded() { public func updateImageIfNeeded() {
let frame = animator?.activeFrame() ?? image if var imageContainer = self as? ImageContainer {
if image != frame { image = frame } imageContainer.image = activeFrame ?? imageContainer.image
} else {
layer.contents = activeFrame?.cgImage
}
} }
} }

View File

@ -0,0 +1,2 @@
/// Makes `UIImageView` conform to `ImageContainer`
extension UIImageView: ImageContainer {}

View File

@ -45,6 +45,9 @@
<li class="nav-group-task"> <li class="nav-group-task">
<a href="Protocols/GIFAnimatable.html">GIFAnimatable</a> <a href="Protocols/GIFAnimatable.html">GIFAnimatable</a>
</li> </li>
<li class="nav-group-task">
<a href="Protocols/ImageContainer.html">ImageContainer</a>
</li>
</ul> </ul>
</li> </li>
</ul> </ul>

View File

@ -46,6 +46,9 @@
<li class="nav-group-task"> <li class="nav-group-task">
<a href="../Protocols/GIFAnimatable.html">GIFAnimatable</a> <a href="../Protocols/GIFAnimatable.html">GIFAnimatable</a>
</li> </li>
<li class="nav-group-task">
<a href="../Protocols/ImageContainer.html">ImageContainer</a>
</li>
</ul> </ul>
</li> </li>
</ul> </ul>

View File

@ -46,6 +46,9 @@
<li class="nav-group-task"> <li class="nav-group-task">
<a href="../Protocols/GIFAnimatable.html">GIFAnimatable</a> <a href="../Protocols/GIFAnimatable.html">GIFAnimatable</a>
</li> </li>
<li class="nav-group-task">
<a href="../Protocols/ImageContainer.html">ImageContainer</a>
</li>
</ul> </ul>
</li> </li>
</ul> </ul>

View File

@ -45,6 +45,9 @@
<li class="nav-group-task"> <li class="nav-group-task">
<a href="Protocols/GIFAnimatable.html">GIFAnimatable</a> <a href="Protocols/GIFAnimatable.html">GIFAnimatable</a>
</li> </li>
<li class="nav-group-task">
<a href="Protocols/ImageContainer.html">ImageContainer</a>
</li>
</ul> </ul>
</li> </li>
</ul> </ul>
@ -87,6 +90,34 @@
</section> </section>
</div> </div>
</li> </li>
<li class="item">
<div>
<code>
<a name="/s:P4Gifu14ImageContainer"></a>
<a name="//apple_ref/swift/Protocol/ImageContainer" class="dashAnchor"></a>
<a class="token" href="#/s:P4Gifu14ImageContainer">ImageContainer</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>A single-property protocol that animatable classes can optionally conform to.</p>
<a href="Protocols/ImageContainer.html" class="slightly-smaller">See more</a>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight"><code><span class="kd">public</span> <span class="kd">protocol</span> <span class="kt">ImageContainer</span></code></pre>
</div>
</div>
</section>
</div>
</li>
</ul> </ul>
</div> </div>
</section> </section>

View File

@ -46,6 +46,9 @@
<li class="nav-group-task"> <li class="nav-group-task">
<a href="../Protocols/GIFAnimatable.html">GIFAnimatable</a> <a href="../Protocols/GIFAnimatable.html">GIFAnimatable</a>
</li> </li>
<li class="nav-group-task">
<a href="../Protocols/ImageContainer.html">ImageContainer</a>
</li>
</ul> </ul>
</li> </li>
</ul> </ul>
@ -93,33 +96,6 @@
</section> </section>
</div> </div>
</li> </li>
<li class="item">
<div>
<code>
<a name="/s:vP4Gifu13GIFAnimatable5imageGSqCSo7UIImage_"></a>
<a name="//apple_ref/swift/Property/image" class="dashAnchor"></a>
<a class="token" href="#/s:vP4Gifu13GIFAnimatable5imageGSqCSo7UIImage_">image</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Used for displaying the animation frames.</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight"><code><span class="k">var</span> <span class="nv">image</span><span class="p">:</span> <span class="kt">UIImage</span><span class="p">?</span></code></pre>
</div>
</div>
</section>
</div>
</li>
<li class="item"> <li class="item">
<div> <div>
<code> <code>
@ -208,9 +184,9 @@
<li class="item"> <li class="item">
<div> <div>
<code> <code>
<a name="/s:vE4GifuPS_13GIFAnimatable20intrinsicContentSizeVSC6CGSize"></a> <a name="/s:ve4GifuRxS_13GIFAnimatablexS_14ImageContainerrS0_20intrinsicContentSizeVSC6CGSize"></a>
<a name="//apple_ref/swift/Property/intrinsicContentSize" class="dashAnchor"></a> <a name="//apple_ref/swift/Property/intrinsicContentSize" class="dashAnchor"></a>
<a class="token" href="#/s:vE4GifuPS_13GIFAnimatable20intrinsicContentSizeVSC6CGSize">intrinsicContentSize</a> <a class="token" href="#/s:ve4GifuRxS_13GIFAnimatablexS_14ImageContainerrS0_20intrinsicContentSizeVSC6CGSize">intrinsicContentSize</a>
</code> </code>
<span class="declaration-note"> <span class="declaration-note">
Extension method Extension method
@ -235,6 +211,10 @@
</section> </section>
</div> </div>
</li> </li>
</ul>
</div>
<div class="task-group">
<ul>
<li class="item"> <li class="item">
<div> <div>
<code> <code>

View File

@ -0,0 +1,111 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>ImageContainer Protocol Reference</title>
<link rel="stylesheet" type="text/css" href="../css/jazzy.css" />
<link rel="stylesheet" type="text/css" href="../css/highlight.css" />
<meta charset='utf-8'>
<script src="../js/jquery.min.js" defer></script>
<script src="../js/jazzy.js" defer></script>
</head>
<body>
<a name="//apple_ref/swift/Protocol/ImageContainer" class="dashAnchor"></a>
<a title="ImageContainer Protocol Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="../index.html">Gifu Docs</a> (100% documented)</p>
<p class="header-right"><a href="https://github.com/kaishin/gifu/"><img src="../img/gh.png"/>View on GitHub</a></p>
<p class="header-right"><a href="dash-feed://https%3A%2F%2Fpyroh%2Egithub%2Eio%2Fdocsets%2FGifu%2Exml"><img src="../img/dash.png"/>Install in Dash</a></p>
</div>
</header>
<div class="content-wrapper">
<p id="breadcrumbs">
<a href="../index.html">Gifu Reference</a>
<img id="carat" src="../img/carat.png" />
ImageContainer Protocol Reference
</p>
</div>
<div class="content-wrapper">
<nav class="sidebar">
<ul class="nav-groups">
<li class="nav-group-name">
<a href="../Classes.html">Classes</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="../Classes/Animator.html">Animator</a>
</li>
<li class="nav-group-task">
<a href="../Classes/GIFImageView.html">GIFImageView</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="../Protocols.html">Protocols</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="../Protocols/GIFAnimatable.html">GIFAnimatable</a>
</li>
<li class="nav-group-task">
<a href="../Protocols/ImageContainer.html">ImageContainer</a>
</li>
</ul>
</li>
</ul>
</nav>
<article class="main-content">
<section>
<section class="section">
<h1>ImageContainer</h1>
<div class="declaration">
<div class="language">
<pre class="highlight"><code><span class="kd">public</span> <span class="kd">protocol</span> <span class="kt">ImageContainer</span></code></pre>
</div>
</div>
<p>A single-property protocol that animatable classes can optionally conform to.</p>
</section>
<section class="section task-group-section">
<div class="task-group">
<ul>
<li class="item">
<div>
<code>
<a name="/s:vP4Gifu14ImageContainer5imageGSqCSo7UIImage_"></a>
<a name="//apple_ref/swift/Property/image" class="dashAnchor"></a>
<a class="token" href="#/s:vP4Gifu14ImageContainer5imageGSqCSo7UIImage_">image</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Used for displaying the animation frames.</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight"><code><span class="k">var</span> <span class="nv">image</span><span class="p">:</span> <span class="kt">UIImage</span><span class="p">?</span></code></pre>
</div>
</div>
</section>
</div>
</li>
</ul>
</div>
</section>
</section>
<section id="footer">
<p>2015 © Reda Lemeden. See LICENSE for more details.</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.7.2</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
</div>
</body>
</div>
</html>

View File

@ -45,6 +45,9 @@
<li class="nav-group-task"> <li class="nav-group-task">
<a href="Protocols/GIFAnimatable.html">GIFAnimatable</a> <a href="Protocols/GIFAnimatable.html">GIFAnimatable</a>
</li> </li>
<li class="nav-group-task">
<a href="Protocols/ImageContainer.html">ImageContainer</a>
</li>
</ul> </ul>
</li> </li>
</ul> </ul>

View File

@ -46,6 +46,9 @@
<li class="nav-group-task"> <li class="nav-group-task">
<a href="../Protocols/GIFAnimatable.html">GIFAnimatable</a> <a href="../Protocols/GIFAnimatable.html">GIFAnimatable</a>
</li> </li>
<li class="nav-group-task">
<a href="../Protocols/ImageContainer.html">ImageContainer</a>
</li>
</ul> </ul>
</li> </li>
</ul> </ul>

View File

@ -46,6 +46,9 @@
<li class="nav-group-task"> <li class="nav-group-task">
<a href="../Protocols/GIFAnimatable.html">GIFAnimatable</a> <a href="../Protocols/GIFAnimatable.html">GIFAnimatable</a>
</li> </li>
<li class="nav-group-task">
<a href="../Protocols/ImageContainer.html">ImageContainer</a>
</li>
</ul> </ul>
</li> </li>
</ul> </ul>

View File

@ -45,6 +45,9 @@
<li class="nav-group-task"> <li class="nav-group-task">
<a href="Protocols/GIFAnimatable.html">GIFAnimatable</a> <a href="Protocols/GIFAnimatable.html">GIFAnimatable</a>
</li> </li>
<li class="nav-group-task">
<a href="Protocols/ImageContainer.html">ImageContainer</a>
</li>
</ul> </ul>
</li> </li>
</ul> </ul>
@ -87,6 +90,34 @@
</section> </section>
</div> </div>
</li> </li>
<li class="item">
<div>
<code>
<a name="/s:P4Gifu14ImageContainer"></a>
<a name="//apple_ref/swift/Protocol/ImageContainer" class="dashAnchor"></a>
<a class="token" href="#/s:P4Gifu14ImageContainer">ImageContainer</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>A single-property protocol that animatable classes can optionally conform to.</p>
<a href="Protocols/ImageContainer.html" class="slightly-smaller">See more</a>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight"><code><span class="kd">public</span> <span class="kd">protocol</span> <span class="kt">ImageContainer</span></code></pre>
</div>
</div>
</section>
</div>
</li>
</ul> </ul>
</div> </div>
</section> </section>

View File

@ -46,6 +46,9 @@
<li class="nav-group-task"> <li class="nav-group-task">
<a href="../Protocols/GIFAnimatable.html">GIFAnimatable</a> <a href="../Protocols/GIFAnimatable.html">GIFAnimatable</a>
</li> </li>
<li class="nav-group-task">
<a href="../Protocols/ImageContainer.html">ImageContainer</a>
</li>
</ul> </ul>
</li> </li>
</ul> </ul>
@ -93,33 +96,6 @@
</section> </section>
</div> </div>
</li> </li>
<li class="item">
<div>
<code>
<a name="/s:vP4Gifu13GIFAnimatable5imageGSqCSo7UIImage_"></a>
<a name="//apple_ref/swift/Property/image" class="dashAnchor"></a>
<a class="token" href="#/s:vP4Gifu13GIFAnimatable5imageGSqCSo7UIImage_">image</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Used for displaying the animation frames.</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight"><code><span class="k">var</span> <span class="nv">image</span><span class="p">:</span> <span class="kt">UIImage</span><span class="p">?</span></code></pre>
</div>
</div>
</section>
</div>
</li>
<li class="item"> <li class="item">
<div> <div>
<code> <code>
@ -208,9 +184,9 @@
<li class="item"> <li class="item">
<div> <div>
<code> <code>
<a name="/s:vE4GifuPS_13GIFAnimatable20intrinsicContentSizeVSC6CGSize"></a> <a name="/s:ve4GifuRxS_13GIFAnimatablexS_14ImageContainerrS0_20intrinsicContentSizeVSC6CGSize"></a>
<a name="//apple_ref/swift/Property/intrinsicContentSize" class="dashAnchor"></a> <a name="//apple_ref/swift/Property/intrinsicContentSize" class="dashAnchor"></a>
<a class="token" href="#/s:vE4GifuPS_13GIFAnimatable20intrinsicContentSizeVSC6CGSize">intrinsicContentSize</a> <a class="token" href="#/s:ve4GifuRxS_13GIFAnimatablexS_14ImageContainerrS0_20intrinsicContentSizeVSC6CGSize">intrinsicContentSize</a>
</code> </code>
<span class="declaration-note"> <span class="declaration-note">
Extension method Extension method
@ -235,6 +211,10 @@
</section> </section>
</div> </div>
</li> </li>
</ul>
</div>
<div class="task-group">
<ul>
<li class="item"> <li class="item">
<div> <div>
<code> <code>

View File

@ -0,0 +1,111 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>ImageContainer Protocol Reference</title>
<link rel="stylesheet" type="text/css" href="../css/jazzy.css" />
<link rel="stylesheet" type="text/css" href="../css/highlight.css" />
<meta charset='utf-8'>
<script src="../js/jquery.min.js" defer></script>
<script src="../js/jazzy.js" defer></script>
</head>
<body>
<a name="//apple_ref/swift/Protocol/ImageContainer" class="dashAnchor"></a>
<a title="ImageContainer Protocol Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="../index.html">Gifu Docs</a> (100% documented)</p>
<p class="header-right"><a href="https://github.com/kaishin/gifu/"><img src="../img/gh.png"/>View on GitHub</a></p>
<p class="header-right"><a href="dash-feed://https%3A%2F%2Fpyroh%2Egithub%2Eio%2Fdocsets%2FGifu%2Exml"><img src="../img/dash.png"/>Install in Dash</a></p>
</div>
</header>
<div class="content-wrapper">
<p id="breadcrumbs">
<a href="../index.html">Gifu Reference</a>
<img id="carat" src="../img/carat.png" />
ImageContainer Protocol Reference
</p>
</div>
<div class="content-wrapper">
<nav class="sidebar">
<ul class="nav-groups">
<li class="nav-group-name">
<a href="../Classes.html">Classes</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="../Classes/Animator.html">Animator</a>
</li>
<li class="nav-group-task">
<a href="../Classes/GIFImageView.html">GIFImageView</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="../Protocols.html">Protocols</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="../Protocols/GIFAnimatable.html">GIFAnimatable</a>
</li>
<li class="nav-group-task">
<a href="../Protocols/ImageContainer.html">ImageContainer</a>
</li>
</ul>
</li>
</ul>
</nav>
<article class="main-content">
<section>
<section class="section">
<h1>ImageContainer</h1>
<div class="declaration">
<div class="language">
<pre class="highlight"><code><span class="kd">public</span> <span class="kd">protocol</span> <span class="kt">ImageContainer</span></code></pre>
</div>
</div>
<p>A single-property protocol that animatable classes can optionally conform to.</p>
</section>
<section class="section task-group-section">
<div class="task-group">
<ul>
<li class="item">
<div>
<code>
<a name="/s:vP4Gifu14ImageContainer5imageGSqCSo7UIImage_"></a>
<a name="//apple_ref/swift/Property/image" class="dashAnchor"></a>
<a class="token" href="#/s:vP4Gifu14ImageContainer5imageGSqCSo7UIImage_">image</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Used for displaying the animation frames.</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight"><code><span class="k">var</span> <span class="nv">image</span><span class="p">:</span> <span class="kt">UIImage</span><span class="p">?</span></code></pre>
</div>
</div>
</section>
</div>
</li>
</ul>
</div>
</section>
</section>
<section id="footer">
<p>2015 © Reda Lemeden. See LICENSE for more details.</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.7.2</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
</div>
</body>
</div>
</html>

View File

@ -45,6 +45,9 @@
<li class="nav-group-task"> <li class="nav-group-task">
<a href="Protocols/GIFAnimatable.html">GIFAnimatable</a> <a href="Protocols/GIFAnimatable.html">GIFAnimatable</a>
</li> </li>
<li class="nav-group-task">
<a href="Protocols/ImageContainer.html">ImageContainer</a>
</li>
</ul> </ul>
</li> </li>
</ul> </ul>
@ -53,11 +56,11 @@
<section> <section>
<section class="section"> <section class="section">
<h1><img src="https://github.com/kaishin/Gifu/raw/swift3/header.gif" alt="Gifu Logo" style="border-radius: 6px"></h1> <a href='#img-src-https-github-com-kaishin-gifu-raw-master-header-gif-alt-logo' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h1 id='img-src-https-github-com-kaishin-gifu-raw-master-header-gif-alt-logo'><img src="https://github.com/kaishin/Gifu/raw/master/header.gif" alt="Logo"></h1>
<p><a href="https://github.com/kaishin/Gifu/releases/latest"><img src="https://img.shields.io/github/release/kaishin/Gifu.svg?maxAge=2592000" alt="GitHub release"></a> <a href="https://travis-ci.org/kaishin/Gifu"><img src="https://travis-ci.org/kaishin/Gifu.svg?branch=master" alt="Travis"></a> <a href="https://github.com/Carthage/Carthage"><img src="https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat" alt="Carthage compatible"></a> <a href="https://gitter.im/kaishin/gifu"><img src="https://badges.gitter.im/kaishin/gifu.svg" alt="Join the chat at https://gitter.im/kaishin/gifu"></a> <img src="https://img.shields.io/badge/Swift-3.0.x-orange.svg" alt="Swift 3.0.x"> <img src="https://img.shields.io/badge/platforms-iOS-lightgrey.svg" alt="platforms"></p> <p><a href="https://github.com/kaishin/Gifu/releases/latest"><img src="https://img.shields.io/github/release/kaishin/Gifu.svg?maxAge=2592000" alt="GitHub release"></a> <a href="https://travis-ci.org/kaishin/Gifu"><img src="https://travis-ci.org/kaishin/Gifu.svg?branch=master" alt="Travis"></a> <a href="https://github.com/Carthage/Carthage"><img src="https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat" alt="Carthage compatible"></a> <a href="https://gitter.im/kaishin/gifu"><img src="https://badges.gitter.im/kaishin/gifu.svg" alt="Join the chat at https://gitter.im/kaishin/gifu"></a> <img src="https://img.shields.io/badge/Swift-3.0.x-orange.svg" alt="Swift 3.0.x"> <img src="https://img.shields.io/badge/platforms-iOS-lightgrey.svg" alt="platforms"></p>
<p>Gifu adds protocol-based, performance-aware animated GIF support to UIKit, without forcing you to use a <code>UIImageView</code> subclass. (It&rsquo;s also a <a href="https://goo.gl/maps/CCeAc">prefecture in Japan</a>).</p> <p>Gifu adds protocol-based, performance-aware animated GIF support to UIKit. (It&rsquo;s also a <a href="https://goo.gl/maps/CCeAc">prefecture in Japan</a>).</p>
<p><strong>Swift 2.3</strong> support is on the <a href="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><strong>Swift 2.3</strong> support is on the <a href="https://github.com/kaishin/Gifu/tree/swift2.3">swift2.3</a> branch. <strong>This branch will not be getting any future updates</strong>.</p>
<a href='#install' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='install'>Install</h2> <a href='#install' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='install'>Install</h2>
@ -78,7 +81,7 @@ for up to date installation instructions.</li>
</ul> </ul>
<a href='#how-it-works' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='how-it-works'>How It Works</h2> <a href='#how-it-works' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='how-it-works'>How It Works</h2>
<p><code>Gifu</code> does not rely on subclassing <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><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 <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>
@ -92,7 +95,7 @@ containing 10 frames, Gifu will load the current frame (red), buffer the next tw
<ul> <ul>
<li>Use the built-in <code>GIFImageView</code> subclass.</li> <li>Use the built-in <code>GIFImageView</code> subclass.</li>
<li>Make <code>UIImageView</code> or any of its subclasses conform to <code>GIFAnimatable</code>.</li> <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>
</ul> </ul>
<a href='#gifimageview' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='gifimageview'>GIFImageView</h3> <a href='#gifimageview' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='gifimageview'>GIFImageView</h3>
@ -121,6 +124,12 @@ containing 10 frames, Gifu will load the current frame (red), buffer the next tw
<li><code>prepareForReuse()</code> to free up resources.</li> <li><code>prepareForReuse()</code> to free up resources.</li>
<li><code>updateImageIfNeeded()</code> to update the image property if necessary.</li> <li><code>updateImageIfNeeded()</code> to update the image property if necessary.</li>
</ul> </ul>
<p>This approach is especially powerful when you want to combine the functionality of different image libraries.</p>
<pre class="highlight swift"><code><span class="kd">class</span> <span class="kt">MyImageView</span><span class="p">:</span> <span class="kt">OtherImageClass</span><span class="p">,</span> <span class="kt">GIFAnimatable</span> <span class="p">{}</span>
</code></pre>
<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>
<a href='#examples' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='examples'>Examples</h3> <a href='#examples' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='examples'>Examples</h3>
<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>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>

Binary file not shown.

View File

@ -45,6 +45,9 @@
<li class="nav-group-task"> <li class="nav-group-task">
<a href="Protocols/GIFAnimatable.html">GIFAnimatable</a> <a href="Protocols/GIFAnimatable.html">GIFAnimatable</a>
</li> </li>
<li class="nav-group-task">
<a href="Protocols/ImageContainer.html">ImageContainer</a>
</li>
</ul> </ul>
</li> </li>
</ul> </ul>
@ -53,11 +56,11 @@
<section> <section>
<section class="section"> <section class="section">
<h1><img src="https://github.com/kaishin/Gifu/raw/swift3/header.gif" alt="Gifu Logo" style="border-radius: 6px"></h1> <a href='#img-src-https-github-com-kaishin-gifu-raw-master-header-gif-alt-logo' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h1 id='img-src-https-github-com-kaishin-gifu-raw-master-header-gif-alt-logo'><img src="https://github.com/kaishin/Gifu/raw/master/header.gif" alt="Logo"></h1>
<p><a href="https://github.com/kaishin/Gifu/releases/latest"><img src="https://img.shields.io/github/release/kaishin/Gifu.svg?maxAge=2592000" alt="GitHub release"></a> <a href="https://travis-ci.org/kaishin/Gifu"><img src="https://travis-ci.org/kaishin/Gifu.svg?branch=master" alt="Travis"></a> <a href="https://github.com/Carthage/Carthage"><img src="https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat" alt="Carthage compatible"></a> <a href="https://gitter.im/kaishin/gifu"><img src="https://badges.gitter.im/kaishin/gifu.svg" alt="Join the chat at https://gitter.im/kaishin/gifu"></a> <img src="https://img.shields.io/badge/Swift-3.0.x-orange.svg" alt="Swift 3.0.x"> <img src="https://img.shields.io/badge/platforms-iOS-lightgrey.svg" alt="platforms"></p> <p><a href="https://github.com/kaishin/Gifu/releases/latest"><img src="https://img.shields.io/github/release/kaishin/Gifu.svg?maxAge=2592000" alt="GitHub release"></a> <a href="https://travis-ci.org/kaishin/Gifu"><img src="https://travis-ci.org/kaishin/Gifu.svg?branch=master" alt="Travis"></a> <a href="https://github.com/Carthage/Carthage"><img src="https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat" alt="Carthage compatible"></a> <a href="https://gitter.im/kaishin/gifu"><img src="https://badges.gitter.im/kaishin/gifu.svg" alt="Join the chat at https://gitter.im/kaishin/gifu"></a> <img src="https://img.shields.io/badge/Swift-3.0.x-orange.svg" alt="Swift 3.0.x"> <img src="https://img.shields.io/badge/platforms-iOS-lightgrey.svg" alt="platforms"></p>
<p>Gifu adds protocol-based, performance-aware animated GIF support to UIKit, without forcing you to use a <code>UIImageView</code> subclass. (It&rsquo;s also a <a href="https://goo.gl/maps/CCeAc">prefecture in Japan</a>).</p> <p>Gifu adds protocol-based, performance-aware animated GIF support to UIKit. (It&rsquo;s also a <a href="https://goo.gl/maps/CCeAc">prefecture in Japan</a>).</p>
<p><strong>Swift 2.3</strong> support is on the <a href="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><strong>Swift 2.3</strong> support is on the <a href="https://github.com/kaishin/Gifu/tree/swift2.3">swift2.3</a> branch. <strong>This branch will not be getting any future updates</strong>.</p>
<a href='#install' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='install'>Install</h2> <a href='#install' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='install'>Install</h2>
@ -78,7 +81,7 @@ for up to date installation instructions.</li>
</ul> </ul>
<a href='#how-it-works' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='how-it-works'>How It Works</h2> <a href='#how-it-works' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='how-it-works'>How It Works</h2>
<p><code>Gifu</code> does not rely on subclassing <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><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 <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>
@ -92,7 +95,7 @@ containing 10 frames, Gifu will load the current frame (red), buffer the next tw
<ul> <ul>
<li>Use the built-in <code>GIFImageView</code> subclass.</li> <li>Use the built-in <code>GIFImageView</code> subclass.</li>
<li>Make <code>UIImageView</code> or any of its subclasses conform to <code>GIFAnimatable</code>.</li> <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>
</ul> </ul>
<a href='#gifimageview' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='gifimageview'>GIFImageView</h3> <a href='#gifimageview' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='gifimageview'>GIFImageView</h3>
@ -121,6 +124,12 @@ containing 10 frames, Gifu will load the current frame (red), buffer the next tw
<li><code>prepareForReuse()</code> to free up resources.</li> <li><code>prepareForReuse()</code> to free up resources.</li>
<li><code>updateImageIfNeeded()</code> to update the image property if necessary.</li> <li><code>updateImageIfNeeded()</code> to update the image property if necessary.</li>
</ul> </ul>
<p>This approach is especially powerful when you want to combine the functionality of different image libraries.</p>
<pre class="highlight swift"><code><span class="kd">class</span> <span class="kt">MyImageView</span><span class="p">:</span> <span class="kt">OtherImageClass</span><span class="p">,</span> <span class="kt">GIFAnimatable</span> <span class="p">{}</span>
</code></pre>
<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>
<a href='#examples' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='examples'>Examples</h3> <a href='#examples' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='examples'>Examples</h3>
<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>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>