Update the behavior for `SDScaledImageForScaleFactor` on animated image

This commit is contained in:
DreamPiggy 2024-05-06 15:23:38 +08:00
parent fb7ded8066
commit 7bf6a59524
2 changed files with 11 additions and 4 deletions

View File

@ -84,7 +84,11 @@ inline UIImage * _Nullable SDScaledImageForScaleFactor(CGFloat scale, UIImage *
}
}
}
if (!scaledImage && image.sd_isAnimated) {
if (scaledImage) {
SDImageCopyAssociatedObject(image, scaledImage);
return scaledImage;
}
if (image.sd_isAnimated) {
UIImage *animatedImage;
#if SD_UIKIT || SD_WATCH
// `UIAnimatedImage` images share the same size and scale.
@ -120,9 +124,12 @@ inline UIImage * _Nullable SDScaledImageForScaleFactor(CGFloat scale, UIImage *
scaledImage = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:kCGImagePropertyOrientationUp];
#endif
}
SDImageCopyAssociatedObject(image, scaledImage);
if (scaledImage) {
SDImageCopyAssociatedObject(image, scaledImage);
return scaledImage;
}
return scaledImage;
return nil;
}
#pragma mark - Context option

View File

@ -38,7 +38,7 @@
* Returns the underlaying `NSBitmapImageRep` or `SDAnimatedImageRep` frame count.
* Returns 1 for static image.
* SDAnimatedImage:
* Returns `animatedImageFrameCount`
* Returns `animatedImageFrameCount` for animated image, 1 for static image.
*/
@property (nonatomic, assign, readonly) NSUInteger sd_imageFrameCount;