diff --git a/SDWebImage/Core/SDAnimatedImagePlayer.m b/SDWebImage/Core/SDAnimatedImagePlayer.m index 36ca4915..b6d07f42 100644 --- a/SDWebImage/Core/SDAnimatedImagePlayer.m +++ b/SDWebImage/Core/SDAnimatedImagePlayer.m @@ -242,6 +242,18 @@ NSUInteger currentFrameIndex = self.currentFrameIndex; NSUInteger nextFrameIndex = (currentFrameIndex + 1) % totalFrameCount; + switch (self.playbackMode) { + case SDAnimatedImagePlaybackModeNormal: + nextFrameIndex = (currentFrameIndex + 1) % totalFrameCount; + break; + case SDAnimatedImagePlaybackModeReverse: { + nextFrameIndex = (currentFrameIndex - 1) % totalFrameCount; + } + break; + default: + break; + } + // Check if we need to display new frame firstly BOOL bufferFull = NO; if (self.needsDisplayWhenImageBecomesAvailable) { diff --git a/SDWebImage/Core/SDAnimatedImageView.h b/SDWebImage/Core/SDAnimatedImageView.h index c40e36a5..751e4a91 100644 --- a/SDWebImage/Core/SDAnimatedImageView.h +++ b/SDWebImage/Core/SDAnimatedImageView.h @@ -53,6 +53,10 @@ `< 0.0` is not supported currently and stop animation. (may support reverse playback in the future) */ @property (nonatomic, assign) double playbackRate; + +/// The animation playback mode. Default mode is SDAnimatedImagePlaybackModeNormal. +@property (nonatomic, assign) SDAnimatedImagePlaybackMode playbackMode; + /** Provide a max buffer size by bytes. This is used to adjust frame buffer count and can be useful when the decoding cost is expensive (such as Animated WebP software decoding). Default is 0. `0` means automatically adjust by calculating current memory usage. @@ -89,11 +93,6 @@ */ @property (nonatomic, assign) BOOL autoPlayAnimatedImage; -/** - The animation player. - */ -@property (nonatomic, strong, readonly, nullable) SDAnimatedImagePlayer *player; - /** You can specify a runloop mode to let it rendering. Default is NSRunLoopCommonModes on multi-core device, NSDefaultRunLoopMode on single-core device diff --git a/SDWebImage/Core/SDAnimatedImageView.m b/SDWebImage/Core/SDAnimatedImageView.m index 8e79747a..a8c7549a 100644 --- a/SDWebImage/Core/SDAnimatedImageView.m +++ b/SDWebImage/Core/SDAnimatedImageView.m @@ -163,6 +163,9 @@ // Play Rate self.player.playbackRate = self.playbackRate; + // Play Mode + self.player.playbackMode = self.playbackMode; + // Setup handler @weakify(self); self.player.animationFrameHandler = ^(NSUInteger index, UIImage * frame) {