diff --git a/Source/Classes/Animator.swift b/Source/Classes/Animator.swift index 9aad274..0646adf 100644 --- a/Source/Classes/Animator.swift +++ b/Source/Classes/Animator.swift @@ -8,7 +8,7 @@ public class Animator { var shouldResizeFrames = false /// Responsible for loading individual frames and resizing them if necessary. - var frameStore: FrameStore? + private var frameStore: FrameStore? /// Tracks whether the display link is initialized. private var displayLinkInitialized: Bool = false diff --git a/Source/Classes/GIFAnimatable.swift b/Source/Classes/GIFAnimatable.swift index d9e4c15..cc18ed2 100644 --- a/Source/Classes/GIFAnimatable.swift +++ b/Source/Classes/GIFAnimatable.swift @@ -76,7 +76,6 @@ extension GIFAnimatable { animator?.prepareForAnimation(withGIFData: imageData, size: frame.size, contentMode: contentMode) } - /// Stop animating and free up GIF data from memory. public func prepareForReuse() { animator?.prepareForReuse() @@ -92,6 +91,20 @@ extension GIFAnimatable { animator?.stopAnimating() } + /// Whether the frame images should be resized or not. The default is `false`, which means that the frame images retain their original size. + /// + /// - parameter resize: Boolean value indicating whether individual frames should be resized. + public func setShouldResizeFrames(_ resize: Bool) { + animator?.shouldResizeFrames = resize + } + + /// Sets the number of frames that should be buffered. Default is 50. A high number will result in more memory usage and less CPU load, and vice versa. + /// + /// - parameter frames: The number of frames to buffer. + public func setFrameBufferCount(_ frames: Int) { + animator?.frameBufferCount = frames + } + /// Updates the image with a new frame if necessary. public func updateImageIfNeeded() { if var imageContainer = self as? ImageContainer { diff --git a/Supporting Files/Info.plist b/Supporting Files/Info.plist index f3ced5d..158b348 100644 --- a/Supporting Files/Info.plist +++ b/Supporting Files/Info.plist @@ -19,7 +19,7 @@ CFBundleSignature ???? CFBundleVersion - 132 + 119 NSPrincipalClass diff --git a/docs/Protocols/GIFAnimatable.html b/docs/Protocols/GIFAnimatable.html index caf7cc3..ae178c8 100644 --- a/docs/Protocols/GIFAnimatable.html +++ b/docs/Protocols/GIFAnimatable.html @@ -595,6 +595,106 @@ +
  • +
    + + + + setShouldResizeFrames(_:) + + + Extension method + +
    +
    +
    +
    +
    +
    +

    Whether the frame images should be resized or not. The default is false, which means that the frame images retain their original size.

    + +
    +
    +

    Declaration

    +
    +

    Swift

    +
    public func setShouldResizeFrames(_ resize: Bool)
    + +
    +
    +
    +

    Parameters

    + + + + + + + +
    + + resize + + +
    +

    Boolean value indicating whether individual frames should be resized.

    + +
    +
    +
    +
    +
    +
  • +
  • +
    + + + + setFrameBufferCount(_:) + + + Extension method + +
    +
    +
    +
    +
    +
    +

    Sets the number of frames that should be buffered. Default is 50. A high number will result in more memory usage and less CPU load, and vice versa.

    + +
    +
    +

    Declaration

    +
    +

    Swift

    +
    public func setFrameBufferCount(_ frames: Int)
    + +
    +
    +
    +

    Parameters

    + + + + + + + +
    + + frames + + +
    +

    The number of frames to buffer.

    + +
    +
    +
    +
    +
    +
  • diff --git a/docs/docsets/Gifu.docset/Contents/Resources/Documents/Protocols/GIFAnimatable.html b/docs/docsets/Gifu.docset/Contents/Resources/Documents/Protocols/GIFAnimatable.html index caf7cc3..ae178c8 100644 --- a/docs/docsets/Gifu.docset/Contents/Resources/Documents/Protocols/GIFAnimatable.html +++ b/docs/docsets/Gifu.docset/Contents/Resources/Documents/Protocols/GIFAnimatable.html @@ -595,6 +595,106 @@
  • +
  • +
    + + + + setShouldResizeFrames(_:) + + + Extension method + +
    +
    +
    +
    +
    +
    +

    Whether the frame images should be resized or not. The default is false, which means that the frame images retain their original size.

    + +
    +
    +

    Declaration

    +
    +

    Swift

    +
    public func setShouldResizeFrames(_ resize: Bool)
    + +
    +
    +
    +

    Parameters

    + + + + + + + +
    + + resize + + +
    +

    Boolean value indicating whether individual frames should be resized.

    + +
    +
    +
    +
    +
    +
  • +
  • +
    + + + + setFrameBufferCount(_:) + + + Extension method + +
    +
    +
    +
    +
    +
    +

    Sets the number of frames that should be buffered. Default is 50. A high number will result in more memory usage and less CPU load, and vice versa.

    + +
    +
    +

    Declaration

    +
    +

    Swift

    +
    public func setFrameBufferCount(_ frames: Int)
    + +
    +
    +
    +

    Parameters

    + + + + + + + +
    + + frames + + +
    +

    The number of frames to buffer.

    + +
    +
    +
    +
    +
    +
  • diff --git a/docs/docsets/Gifu.docset/Contents/Resources/Documents/index.html b/docs/docsets/Gifu.docset/Contents/Resources/Documents/index.html index 3338e27..b84b1c3 100644 --- a/docs/docsets/Gifu.docset/Contents/Resources/Documents/index.html +++ b/docs/docsets/Gifu.docset/Contents/Resources/Documents/index.html @@ -63,6 +63,8 @@

    Gifu adds protocol-based, performance-aware animated GIF support to UIKit. (It’s also a prefecture in Japan).

    Swift 2.3 support is on the swift2.3 branch. This branch will not be getting any future updates.

    + +

    ⚠ What follows applies to the yet unreleased 2.0 on master.

    Install

    Carthage

    @@ -81,7 +83,7 @@ for up to date installation instructions.
  • How It Works

    -

    Gifu does not force you to use a specific subclass of UIImageView. The Animator class does the heavy-lifting, while the GIFAnimatable protocol exposes the functionality to the view classes that conform to it, using protocol extensions.

    +

    Gifu does not force you to use the built-in GIFImageView subclass. The Animator does the heavy-lifting, while the GIFAnimatable protocol exposes the functionality to the view classes that conform to it, using protocol extensions.

    The Animator has a FrameStore 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.

    @@ -94,15 +96,12 @@ containing 10 frames, Gifu will load the current frame (red), buffer the next tw

    There are two options that should cover any situation:

    -

    GIFImageView

    - -

    A subclass of UIImageView that conforms to GIFAnimatable. You can use this class as-is or subclass it for further customization (not recommended).

    GIFAnimatable

    -

    The bread and butter of Gifu. Through protocol extensions, GIFAnimatable exposes all the APIs of the library, and with very little boilerplate, any UIImageView subclass can conform to it.

    +

    The bread and butter of Gifu. Through protocol extensions, GIFAnimatable exposes all the APIs of the library, and with very little boilerplate, any class can conform to it.

    class MyImageView: UIImageView, GIFAnimatable {
       public lazy var animator: Animator? = {
         return Animator(withDelegate: self)
    @@ -114,7 +113,7 @@ containing 10 frames, Gifu will load the current frame (red), buffer the next tw
     }
     
    -

    That’s it. Now MyImageView is fully GIF-compatible, and any of these methods can be called on it:

    +

    That’s it. Now MyImageView has access to all these methods and properties:

    -

    This approach is especially powerful when you want to combine the functionality of different image libraries.

    -
    class MyImageView: OtherImageClass, GIFAnimatable {}
    +

    Furthermore, you can make any class GIF-animatable, starting with UIView subclasses:

    +
    class CustomAnimatedView: UIView, GIFAnimatable {
    +  public lazy var animator: Animator? = {
    +    return Animator(withDelegate: self)
    +  }()
    +
    +  override public func display(_ layer: CALayer) {
    +    updateImageIfNeeded()
    +  }
    +}
     

    Keep in mind that you need to have control over the class implementing GIFAnimatable since you cannot add the stored Animator property in an extension.

    diff --git a/docs/docsets/Gifu.docset/Contents/Resources/docSet.dsidx b/docs/docsets/Gifu.docset/Contents/Resources/docSet.dsidx index 4ca826a..424df3f 100644 Binary files a/docs/docsets/Gifu.docset/Contents/Resources/docSet.dsidx and b/docs/docsets/Gifu.docset/Contents/Resources/docSet.dsidx differ diff --git a/docs/docsets/Gifu.tgz b/docs/docsets/Gifu.tgz index 9aa4e69..44b8399 100644 Binary files a/docs/docsets/Gifu.tgz and b/docs/docsets/Gifu.tgz differ diff --git a/docs/index.html b/docs/index.html index 3338e27..b84b1c3 100644 --- a/docs/index.html +++ b/docs/index.html @@ -63,6 +63,8 @@

    Gifu adds protocol-based, performance-aware animated GIF support to UIKit. (It’s also a prefecture in Japan).

    Swift 2.3 support is on the swift2.3 branch. This branch will not be getting any future updates.

    + +

    ⚠ What follows applies to the yet unreleased 2.0 on master.

    Install

    Carthage

    @@ -81,7 +83,7 @@ for up to date installation instructions.

    How It Works

    -

    Gifu does not force you to use a specific subclass of UIImageView. The Animator class does the heavy-lifting, while the GIFAnimatable protocol exposes the functionality to the view classes that conform to it, using protocol extensions.

    +

    Gifu does not force you to use the built-in GIFImageView subclass. The Animator does the heavy-lifting, while the GIFAnimatable protocol exposes the functionality to the view classes that conform to it, using protocol extensions.

    The Animator has a FrameStore 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.

    @@ -94,15 +96,12 @@ containing 10 frames, Gifu will load the current frame (red), buffer the next tw

    There are two options that should cover any situation:

      -
    • Use the built-in GIFImageView subclass.
    • -
    • Make any class conform to GIFAnimatable. Subclassing UIImageView is the easiest since you get most of the required properties for free.
    • +
    • Use the built-in GIFImageView subclass if you don’t need to combine GIF support with another image library.
    • +
    • If you need more flexibility and composability, make your class conform to GIFAnimatable. In practice, any UIView subclass would do, since you get most of the required properties for free. For best results, make your UIImageView subclass conform to GIFAnimatable to get other niceties such as intrinsic content size.
    -

    GIFImageView

    - -

    A subclass of UIImageView that conforms to GIFAnimatable. You can use this class as-is or subclass it for further customization (not recommended).

    GIFAnimatable

    -

    The bread and butter of Gifu. Through protocol extensions, GIFAnimatable exposes all the APIs of the library, and with very little boilerplate, any UIImageView subclass can conform to it.

    +

    The bread and butter of Gifu. Through protocol extensions, GIFAnimatable exposes all the APIs of the library, and with very little boilerplate, any class can conform to it.

    class MyImageView: UIImageView, GIFAnimatable {
       public lazy var animator: Animator? = {
         return Animator(withDelegate: self)
    @@ -114,7 +113,7 @@ containing 10 frames, Gifu will load the current frame (red), buffer the next tw
     }
     
    -

    That’s it. Now MyImageView is fully GIF-compatible, and any of these methods can be called on it:

    +

    That’s it. Now MyImageView has access to all these methods and properties:

    • prepareForAnimation(withGIFNamed:) and prepareForAnimation(withGIFData:) to prepare the animator property for animation.
    • @@ -125,8 +124,16 @@ containing 10 frames, Gifu will load the current frame (red), buffer the next tw
    • updateImageIfNeeded() to update the image property if necessary.
    -

    This approach is especially powerful when you want to combine the functionality of different image libraries.

    -
    class MyImageView: OtherImageClass, GIFAnimatable {}
    +

    Furthermore, you can make any class GIF-animatable, starting with UIView subclasses:

    +
    class CustomAnimatedView: UIView, GIFAnimatable {
    +  public lazy var animator: Animator? = {
    +    return Animator(withDelegate: self)
    +  }()
    +
    +  override public func display(_ layer: CALayer) {
    +    updateImageIfNeeded()
    +  }
    +}
     

    Keep in mind that you need to have control over the class implementing GIFAnimatable since you cannot add the stored Animator property in an extension.