diff --git a/Source/Classes/Animator.swift b/Source/Classes/Animator.swift index 1f209ed..9aad274 100644 --- a/Source/Classes/Animator.swift +++ b/Source/Classes/Animator.swift @@ -51,11 +51,10 @@ public class Animator { } } - /// Prepares the animator instance for animation. /// - /// - parameter imageName: The file name of the GIF in the main bundle. - /// - parameter size: The target size of the individual frames. + /// - parameter imageName: The file name of the GIF in the main bundle. + /// - parameter size: The target size of the individual frames. /// - parameter contentMode: The view content mode to use for the individual frames. func prepareForAnimation(withGIFNamed imageName: String, size: CGSize, contentMode: UIViewContentMode) { guard let extensionRemoved = imageName.components(separatedBy: ".")[safe: 0], @@ -67,8 +66,8 @@ public class Animator { /// Prepares the animator instance for animation. /// - /// - parameter imageData: GIF image data. - /// - parameter size: The target size of the individual frames. + /// - parameter imageData: GIF image data. + /// - parameter size: The target size of the individual frames. /// - parameter contentMode: The view content mode to use for the individual frames. func prepareForAnimation(withGIFData imageData: Data, size: CGSize, contentMode: UIViewContentMode) { frameStore = FrameStore(data: imageData, size: size, contentMode: contentMode, framePreloadCount: frameBufferCount) @@ -103,8 +102,8 @@ public class Animator { /// Prepare for animation and start animating immediately. /// - /// - parameter imageName: The file name of the GIF in the main bundle. - /// - parameter size: The target size of the individual frames. + /// - parameter imageName: The file name of the GIF in the main bundle. + /// - parameter size: The target size of the individual frames. /// - parameter contentMode: The view content mode to use for the individual frames. func animate(withGIFNamed imageName: String, size: CGSize, contentMode: UIViewContentMode) { prepareForAnimation(withGIFNamed: imageName, size: size, contentMode: contentMode) @@ -113,11 +112,11 @@ public class Animator { /// Prepare for animation and start animating immediately. /// - /// - parameter imageData: GIF image data. - /// - parameter size: The target size of the individual frames. + /// - parameter imageData: GIF image data. + /// - parameter size: The target size of the individual frames. /// - parameter contentMode: The view content mode to use for the individual frames. - func animate(withGIFData data: Data, size: CGSize, contentMode: UIViewContentMode) { - prepareForAnimation(withGIFData: data, size: size, contentMode: contentMode) + func animate(withGIFData imageData: Data, size: CGSize, contentMode: UIViewContentMode) { + prepareForAnimation(withGIFData: imageData, size: size, contentMode: contentMode) startAnimating() } diff --git a/Source/Classes/GIFAnimatable.swift b/Source/Classes/GIFAnimatable.swift index fb36022..26fe89b 100644 --- a/Source/Classes/GIFAnimatable.swift +++ b/Source/Classes/GIFAnimatable.swift @@ -23,11 +23,14 @@ extension GIFAnimatable { return image?.size ?? CGSize.zero } - /// Prepare for animation and start animating immediately. - /// - /// - parameter imageName: The file name of the GIF in the main bundle. - public func animate(withGIFNamed imageName: String) { - animator?.animate(withGIFNamed: imageName, size: frame.size, contentMode: contentMode) + /// Returns the active frame if available. + public var activeFrame: UIImage? { + return animator?.activeFrame() + } + + /// Total frame count of the GIF. + public var frameCount: Int { + return animator?.frameCount ?? 0 } /// Introspect whether the instance is animating. @@ -35,6 +38,20 @@ extension GIFAnimatable { return animator?.isAnimating ?? false } + /// Prepare for animation and start animating immediately. + /// + /// - parameter imageName: The file name of the GIF in the main bundle. + public func animate(withGIFNamed imageName: String) { + animator?.animate(withGIFNamed: imageName, size: frame.size, contentMode: contentMode) + } + + /// Prepare for animation and start animating immediately. + /// + /// - parameter imageData: GIF image data. + public func animate(withGIFData imageData: Data) { + animator?.animate(withGIFData: imageData, size: frame.size, contentMode: contentMode) + } + /// Prepares the animator instance for animation. /// /// - parameter imageName: The file name of the GIF in the main bundle. @@ -50,10 +67,6 @@ extension GIFAnimatable { animator?.prepareForAnimation(withGIFData: imageData, size: frame.size, contentMode: contentMode) } - /// Total frame count of the GIF. - public var frameCount: Int { - return animator?.frameCount ?? 0 - } /// Stop animating and free up GIF data from memory. public func prepareForReuse() { @@ -74,16 +87,11 @@ extension GIFAnimatable { public func updateImageIfNeeded() { image = animator?.activeFrame() ?? image } - - /// Returns the active frame if available. - public func activeFrame() -> UIImage? { - return animator?.activeFrame() - } } extension GIFAnimatable { /// Calls setNeedsDisplay on the layer whenever the animator has a new frame. Should *not* be called directly. - public func animatorHasNewFrame() { + func animatorHasNewFrame() { layer.setNeedsDisplay() } }