This commit is contained in:
Insomnia 2020-10-27 22:03:41 +08:00
parent 32d2a79cf8
commit 310de419e7
3 changed files with 19 additions and 5 deletions

View File

@ -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) {

View File

@ -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

View File

@ -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) {