Add new properties `clearBufferWhenStopped` and `resetFrameIndexWhenStopped`
This commit is contained in:
parent
2350dcf77d
commit
1abc05e05c
|
@ -58,6 +58,20 @@
|
|||
*/
|
||||
@property (nonatomic, assign) BOOL shouldIncrementalLoad;
|
||||
|
||||
/**
|
||||
Whether or not to clear the frame buffer cache when animation stopped. See `maxBufferSize`
|
||||
This is useful when you want to limit the memory usage during frequently visibility changes (such as image view inside a list view, then push and pop)
|
||||
Default is NO.
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL clearBufferWhenStopped;
|
||||
|
||||
/**
|
||||
Whether or not to reset the current frame index when animation stopped.
|
||||
For some of use case, you may want to reset the frame index to 0 when stop, but some other want to keep the current frame index.
|
||||
Default is NO.
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL resetFrameIndexWhenStopped;
|
||||
|
||||
#if SD_UIKIT
|
||||
/**
|
||||
You can specify a runloop mode to let it rendering.
|
||||
|
|
|
@ -149,21 +149,15 @@ static NSUInteger SDDeviceFreeMemory() {
|
|||
self.animatedImage = nil;
|
||||
self.totalFrameCount = 0;
|
||||
self.totalLoopCount = 0;
|
||||
self.currentFrame = nil;
|
||||
self.currentFrameIndex = 0;
|
||||
self.currentLoopCount = 0;
|
||||
self.currentTime = 0;
|
||||
self.bufferMiss = NO;
|
||||
// reset current state
|
||||
[self resetCurrentFrameIndex];
|
||||
self.shouldAnimate = NO;
|
||||
self.isProgressive = NO;
|
||||
self.maxBufferCount = 0;
|
||||
self.animatedImageScale = 1;
|
||||
[_fetchQueue cancelAllOperations];
|
||||
_fetchQueue = nil;
|
||||
SD_LOCK(self.lock);
|
||||
[_frameBuffer removeAllObjects];
|
||||
_frameBuffer = nil;
|
||||
SD_UNLOCK(self.lock);
|
||||
// clear buffer cache
|
||||
[self clearFrameBuffer];
|
||||
}
|
||||
|
||||
- (void)resetProgressiveImage
|
||||
|
@ -179,6 +173,23 @@ static NSUInteger SDDeviceFreeMemory() {
|
|||
// preserve buffer cache
|
||||
}
|
||||
|
||||
- (void)resetCurrentFrameIndex
|
||||
{
|
||||
self.currentFrame = nil;
|
||||
self.currentFrameIndex = 0;
|
||||
self.currentLoopCount = 0;
|
||||
self.currentTime = 0;
|
||||
self.bufferMiss = NO;
|
||||
}
|
||||
|
||||
- (void)clearFrameBuffer
|
||||
{
|
||||
SD_LOCK(self.lock);
|
||||
[_frameBuffer removeAllObjects];
|
||||
_frameBuffer = nil;
|
||||
SD_UNLOCK(self.lock);
|
||||
}
|
||||
|
||||
#pragma mark - Accessors
|
||||
#pragma mark Public
|
||||
|
||||
|
@ -466,6 +477,12 @@ static NSUInteger SDDeviceFreeMemory() {
|
|||
#else
|
||||
_displayLink.paused = YES;
|
||||
#endif
|
||||
if (self.resetFrameIndexWhenStopped) {
|
||||
[self resetCurrentFrameIndex];
|
||||
}
|
||||
if (self.clearBufferWhenStopped) {
|
||||
[self clearFrameBuffer];
|
||||
}
|
||||
} else {
|
||||
#if SD_UIKIT
|
||||
[super stopAnimating];
|
||||
|
|
Loading…
Reference in New Issue