YYAnimatedImageView

@interface YYAnimatedImageView : UIImageView

An image view for displaying animated image.

@discussion It is a fully compatible UIImageView subclass. If the image or highlightedImage property adopt to the YYAnimatedImage protocol, then it can be used to play the multi-frame animation. The animation can also be controlled with the UIImageView methods -startAnimating, -stopAnimating and -isAnimating.

This view request the frame data just in time. When the device has enough free memory, this view may cache some or all future frames in an inner buffer for lower CPU cost. Buffer size is dynamically adjusted based on the current state of the device memory.

Sample Code:

// [email protected]
YYImage *image = [YYImage imageNamed:@"ani"];
YYAnimatedImageView *imageView = [YYAnimatedImageView alloc] initWithImage:image];
[view addSubView:imageView];
  • If the image has more than one frame, set this value to YES will automatically play/stop the animation when the view become visible/invisible.

    The default value is YES.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) BOOL autoPlayAnimatedImage;

    Swift

    var autoPlayAnimatedImage: Bool { get set }
  • Index of the currently displayed frame (index from 0).

    Set a new value to this property will cause to display the new frame immediately. If the new value is invalid, this method has no effect.

    You can add an observer to this property to observe the playing status.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) NSUInteger currentAnimatedImageIndex;

    Swift

    var currentAnimatedImageIndex: UInt { get set }
  • Whether the image view is playing animation currently.

    You can add an observer to this property to observe the playing status.

    Declaration

    Objective-C

    @property (readonly, nonatomic) BOOL currentIsPlayingAnimation;

    Swift

    var currentIsPlayingAnimation: Bool { get }
  • The animation timer’s runloop mode, default is NSRunLoopCommonModes.

    Set this property to NSDefaultRunLoopMode will make the animation pause during UIScrollView scrolling.

    Declaration

    Objective-C

    @property (readwrite, copy, nonatomic) NSString *_Nonnull runloopMode;

    Swift

    var runloopMode: String { get set }
  • The max size (in bytes) for inner frame buffer size, default is 0 (dynamically).

    When the device has enough free memory, this view will request and decode some or all future frame image into an inner buffer. If this property’s value is 0, then the max buffer size will be dynamically adjusted based on the current state of the device free memory. Otherwise, the buffer size will be limited by this value.

    When receive memory warning or app enter background, the buffer will be released immediately, and may grow back at the right time.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) NSUInteger maxBufferSize;

    Swift

    var maxBufferSize: UInt { get set }