Fix the bug of SDAnimatedImageView, which can not render the normal NSImage (including animated image) at all. Only `SDAnimatedImage` can be rendered

This commit is contained in:
DreamPiggy 2019-04-25 13:23:34 +08:00
parent 072e62b1cb
commit 8c93519191
2 changed files with 17 additions and 3 deletions

View File

@ -29,13 +29,16 @@
// For animated GIF rendering, set `animates` to YES or will only show the first frame // For animated GIF rendering, set `animates` to YES or will only show the first frame
self.imageView2.animates = YES; // `SDAnimatedImageRep` can be used for built-in `NSImageView` to support better GIF & APNG rendering as well. No need `SDAnimatedImageView` self.imageView2.animates = YES; // `SDAnimatedImageRep` can be used for built-in `NSImageView` to support better GIF & APNG rendering as well. No need `SDAnimatedImageView`
self.imageView3.animates = YES;
self.imageView4.animates = YES; self.imageView4.animates = YES;
// NSImageView + Static Image
self.imageView1.sd_imageIndicator = SDWebImageProgressIndicator.defaultIndicator; self.imageView1.sd_imageIndicator = SDWebImageProgressIndicator.defaultIndicator;
[self.imageView1 sd_setImageWithURL:[NSURL URLWithString:@"https://raw.githubusercontent.com/recurser/exif-orientation-examples/master/Landscape_2.jpg"] placeholderImage:nil options:SDWebImageProgressiveLoad]; [self.imageView1 sd_setImageWithURL:[NSURL URLWithString:@"https://raw.githubusercontent.com/recurser/exif-orientation-examples/master/Landscape_2.jpg"] placeholderImage:nil options:SDWebImageProgressiveLoad];
// NSImageView + Animated Image
[self.imageView2 sd_setImageWithURL:[NSURL URLWithString:@"https:raw.githubusercontent.com/onevcat/APNGKit/master/TestImages/APNG-cube.apng"]]; [self.imageView2 sd_setImageWithURL:[NSURL URLWithString:@"https:raw.githubusercontent.com/onevcat/APNGKit/master/TestImages/APNG-cube.apng"]];
[self.imageView3 sd_setImageWithURL:[NSURL URLWithString:@"https://raw.githubusercontent.com/liyong03/YLGIFImage/master/YLGIFImageDemo/YLGIFImageDemo/joy.gif"]]; // SDAnimatedImageView + Static Image
self.imageView4.wantsLayer = YES; [self.imageView3 sd_setImageWithURL:[NSURL URLWithString:@"https://nr-platform.s3.amazonaws.com/uploads/platform/published_extension/branding_icon/275/AmazonS3.png"]];
// SDAnimatedImageView + Animated Image
self.imageView4.sd_imageTransition = SDWebImageTransition.fadeTransition; self.imageView4.sd_imageTransition = SDWebImageTransition.fadeTransition;
[self.imageView4 sd_setImageWithURL:[NSURL URLWithString:@"http://littlesvr.ca/apng/images/SteamEngine.webp"] placeholderImage:nil options:SDWebImageForceTransition]; [self.imageView4 sd_setImageWithURL:[NSURL URLWithString:@"http://littlesvr.ca/apng/images/SteamEngine.webp"] placeholderImage:nil options:SDWebImageForceTransition];

View File

@ -678,6 +678,17 @@ static NSUInteger SDDeviceFreeMemory() {
[super updateLayer]; [super updateLayer];
} }
} }
- (BOOL)wantsUpdateLayer {
// AppKit is different from UIKit, it need extra check before the layer is updated
// When we use the custom animation, the layer.setNeedsDisplay is directly called from display link (See `displayDidRefresh:`). However, for normal image rendering, we must implements and return YES to mark it need display
if (_currentFrame) {
return NO;
} else {
return YES;
}
}
#endif #endif