Add new properties `clearBufferWhenStopped` and `resetFrameIndexWhenStopped`
This commit is contained in:
parent
2350dcf77d
commit
1abc05e05c
|
@ -58,6 +58,20 @@
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, assign) BOOL shouldIncrementalLoad;
|
@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
|
#if SD_UIKIT
|
||||||
/**
|
/**
|
||||||
You can specify a runloop mode to let it rendering.
|
You can specify a runloop mode to let it rendering.
|
||||||
|
|
|
@ -149,21 +149,15 @@ static NSUInteger SDDeviceFreeMemory() {
|
||||||
self.animatedImage = nil;
|
self.animatedImage = nil;
|
||||||
self.totalFrameCount = 0;
|
self.totalFrameCount = 0;
|
||||||
self.totalLoopCount = 0;
|
self.totalLoopCount = 0;
|
||||||
self.currentFrame = nil;
|
// reset current state
|
||||||
self.currentFrameIndex = 0;
|
[self resetCurrentFrameIndex];
|
||||||
self.currentLoopCount = 0;
|
|
||||||
self.currentTime = 0;
|
|
||||||
self.bufferMiss = NO;
|
|
||||||
self.shouldAnimate = NO;
|
self.shouldAnimate = NO;
|
||||||
self.isProgressive = NO;
|
self.isProgressive = NO;
|
||||||
self.maxBufferCount = 0;
|
self.maxBufferCount = 0;
|
||||||
self.animatedImageScale = 1;
|
self.animatedImageScale = 1;
|
||||||
[_fetchQueue cancelAllOperations];
|
[_fetchQueue cancelAllOperations];
|
||||||
_fetchQueue = nil;
|
// clear buffer cache
|
||||||
SD_LOCK(self.lock);
|
[self clearFrameBuffer];
|
||||||
[_frameBuffer removeAllObjects];
|
|
||||||
_frameBuffer = nil;
|
|
||||||
SD_UNLOCK(self.lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)resetProgressiveImage
|
- (void)resetProgressiveImage
|
||||||
|
@ -179,6 +173,23 @@ static NSUInteger SDDeviceFreeMemory() {
|
||||||
// preserve buffer cache
|
// 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 - Accessors
|
||||||
#pragma mark Public
|
#pragma mark Public
|
||||||
|
|
||||||
|
@ -466,6 +477,12 @@ static NSUInteger SDDeviceFreeMemory() {
|
||||||
#else
|
#else
|
||||||
_displayLink.paused = YES;
|
_displayLink.paused = YES;
|
||||||
#endif
|
#endif
|
||||||
|
if (self.resetFrameIndexWhenStopped) {
|
||||||
|
[self resetCurrentFrameIndex];
|
||||||
|
}
|
||||||
|
if (self.clearBufferWhenStopped) {
|
||||||
|
[self clearFrameBuffer];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
#if SD_UIKIT
|
#if SD_UIKIT
|
||||||
[super stopAnimating];
|
[super stopAnimating];
|
||||||
|
|
Loading…
Reference in New Issue