From 7cc90666e822e2440c5546e860a0bc13ab4834dc Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Sun, 27 Sep 2020 14:58:23 +0800 Subject: [PATCH] Fix the issue that SDAnimatedImageView will trigger an empty callback when animation stopped. This will cause some bad effect such as rendering a empty image or placeholder image (especially on iOS 14) --- SDWebImage/Core/SDAnimatedImagePlayer.m | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/SDWebImage/Core/SDAnimatedImagePlayer.m b/SDWebImage/Core/SDAnimatedImagePlayer.m index db5f123a..36ca4915 100644 --- a/SDWebImage/Core/SDAnimatedImagePlayer.m +++ b/SDWebImage/Core/SDAnimatedImagePlayer.m @@ -160,14 +160,14 @@ } } -- (void)resetCurrentFrameIndex { - self.currentFrame = nil; - self.currentFrameIndex = 0; - self.currentLoopCount = 0; - self.currentTime = 0; - self.bufferMiss = NO; - self.needsDisplayWhenImageBecomesAvailable = NO; - [self handleFrameChange]; +- (void)resetCurrentFrameStatus { + // These should not trigger KVO, user don't need to receive an `index == 0, image == nil` callback. + _currentFrame = nil; + _currentFrameIndex = 0; + _currentLoopCount = 0; + _currentTime = 0; + _bufferMiss = NO; + _needsDisplayWhenImageBecomesAvailable = NO; } - (void)clearFrameBuffer { @@ -191,7 +191,8 @@ [_fetchQueue cancelAllOperations]; // Using `_displayLink` here because when UIImageView dealloc, it may trigger `[self stopAnimating]`, we already release the display link in SDAnimatedImageView's dealloc method. [_displayLink stop]; - [self resetCurrentFrameIndex]; + // We need to reset the frame status, but not trigger any handle. This can ensure next time's playing status correct. + [self resetCurrentFrameStatus]; } - (void)pausePlaying {