YYAnimatedImage

@protocol YYAnimatedImage <NSObject>

The YYAnimatedImage protocol declares the required methods for animated image display with YYAnimatedImageView.

Subclass a UIImage and implement this protocol, so that instances of that class can be set to YYAnimatedImageView.image or YYAnimatedImageView.highlightedImage to display animation.

See YYImage and YYFrameImage for example.

  • Total animated frame count. It the frame count is less than 1, then the methods below will be ignored.

    Declaration

    Objective-C

    - (NSUInteger)animatedImageFrameCount;

    Swift

    func animatedImageFrameCount() -> UInt
  • Animation loop count, 0 means infinite looping.

    Declaration

    Objective-C

    - (NSUInteger)animatedImageLoopCount;

    Swift

    func animatedImageLoopCount() -> UInt
  • Bytes per frame (in memory). It may used to optimize memory buffer size.

    Declaration

    Objective-C

    - (NSUInteger)animatedImageBytesPerFrame;

    Swift

    func animatedImageBytesPerFrame() -> UInt
  • Returns the frame image from a specified index. This method may be called on background thread.

    Declaration

    Objective-C

    - (nullable UIImage *)animatedImageFrameAtIndex:(NSUInteger)index;

    Swift

    func animatedImageFrame(at index: UInt) -> UIImage?

    Parameters

    index

    Frame index (zero based).

  • Returns the frames’s duration from a specified index.

    Declaration

    Objective-C

    - (NSTimeInterval)animatedImageDurationAtIndex:(NSUInteger)index;

    Swift

    func animatedImageDuration(at index: UInt) -> TimeInterval

    Parameters

    index

    Frame index (zero based).

  • A rectangle in image coordinates defining the subrectangle of the image that will be displayed. The rectangle should not outside the image’s bounds. It may used to display sprite animation with a single image (sprite sheet).

    Declaration

    Objective-C

    - (CGRect)animatedImageContentsRectAtIndex:(NSUInteger)index;

    Swift

    optional func animatedImageContentsRect(at index: UInt) -> CGRect