SDAnimatedImage

@protocol SDAnimatedImage <SDAnimatedImageProvider>

This is the protocol for SDAnimatedImage class only but not for SDAnimatedImageCoder. If you want to provide a custom animated image class with full advanced function, you can conform to this instead of the base protocol.

  • Initializes and returns the image object with the specified data, scale factor and possible animation decoding options.

    Note

    We use this to create animated image instance for normal animation decoding.

    Declaration

    Objective-C

    - (nullable instancetype)initWithData:(nonnull NSData *)data
                                    scale:(CGFloat)scale
                                  options:(nullable SDImageCoderOptions *)options;

    Swift

    init?(data: Data, scale: CGFloat, options: [SDImageCoderOption : Any]? = nil)

    Parameters

    data

    The data object containing the image data.

    scale

    The scale factor to assume when interpreting the image data. Applying a scale factor of 1.0 results in an image whose size matches the pixel-based dimensions of the image. Applying a different scale factor changes the size of the image as reported by the size property.

    options

    A dictionary containing any animation decoding options.

    Return Value

    An initialized object

  • Initializes the image with an animated coder. You can use the coder to decode the image frame later.

    Note

    We use this with animated coder which conforms to SDProgressiveImageCoder for progressive animation decoding.

    Declaration

    Objective-C

    - (nullable instancetype)initWithAnimatedCoder:
                                 (nonnull id<SDAnimatedImageCoder>)animatedCoder
                                             scale:(CGFloat)scale;

    Swift

    init?(animatedCoder: SDAnimatedImageCoder, scale: CGFloat)

    Parameters

    animatedCoder

    An animated coder which conform SDAnimatedImageCoder protocol

    scale

    The scale factor to assume when interpreting the image data. Applying a scale factor of 1.0 results in an image whose size matches the pixel-based dimensions of the image. Applying a different scale factor changes the size of the image as reported by the size property.

    Return Value

    An initialized object

  • Pre-load all animated image frame into memory. Then later frame image request can directly return the frame for index without decoding. This method may be called on background thread.

    Note

    If one image instance is shared by lots of imageViews, the CPU performance for large animated image will drop down because the request frame index will be random (not in order) and the decoder should take extra effort to keep it re-entrant. You can use this to reduce CPU usage if need. Attention this will consume more memory usage.

    Declaration

    Objective-C

    - (void)preloadAllFrames;

    Swift

    optional func preloadAllFrames()
  • Unload all animated image frame from memory if are already pre-loaded. Then later frame image request need decoding. You can use this to free up the memory usage if need.

    Declaration

    Objective-C

    - (void)unloadAllFrames;

    Swift

    optional func unloadAllFrames()
  • Returns a Boolean value indicating whether all animated image frames are already pre-loaded into memory.

    Declaration

    Objective-C

    @optional
    @property (readonly, getter=isAllFramesLoaded, assign, nonatomic)
        BOOL allFramesLoaded;

    Swift

    optional var isAllFramesLoaded: Bool { get }
  • Return the animated image coder if the image is created with initWithAnimatedCoder:scale: method.

    Note

    We use this with animated coder which conforms to SDProgressiveImageCoder for progressive animation decoding.

    Declaration

    Objective-C

    @optional
    @property (readonly, strong, nonatomic, nullable) id<SDAnimatedImageCoder>
        animatedCoder;

    Swift

    optional var animatedCoder: SDAnimatedImageCoder? { get }