Update the macOS-specify comment and explain the reason of the `imageViewLayer` method. Update macOS 10.14 behavior.
This commit is contained in:
parent
b0862c2d33
commit
8237712d36
|
@ -61,18 +61,12 @@ static NSUInteger SDDeviceFreeMemory() {
|
||||||
#else
|
#else
|
||||||
@property (nonatomic, strong) CADisplayLink *displayLink;
|
@property (nonatomic, strong) CADisplayLink *displayLink;
|
||||||
#endif
|
#endif
|
||||||
// Layer-backed NSImageView use a subview of `NSImageViewContainerView` to do actual layer rendering. We use this layer instead of `self.layer` during animated image rendering.
|
|
||||||
#if SD_MAC
|
|
||||||
@property (nonatomic, strong, readonly) CALayer *imageViewLayer;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation SDAnimatedImageView
|
@implementation SDAnimatedImageView
|
||||||
#if SD_UIKIT
|
#if SD_UIKIT
|
||||||
@dynamic animationRepeatCount;
|
@dynamic animationRepeatCount;
|
||||||
#else
|
|
||||||
@dynamic imageViewLayer;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#pragma mark - Initializers
|
#pragma mark - Initializers
|
||||||
|
@ -239,7 +233,7 @@ static NSUInteger SDDeviceFreeMemory() {
|
||||||
|
|
||||||
[self.layer setNeedsDisplay];
|
[self.layer setNeedsDisplay];
|
||||||
#if SD_MAC
|
#if SD_MAC
|
||||||
[self.layer displayIfNeeded]; // macOS's imageViewLayer is not equal to self.layer. But `[super setImage:]` will impliedly mark it needsDisplay. We call `[self.layer displayIfNeeded]` to immediately refresh the imageViewLayer to avoid flashing
|
[self.layer displayIfNeeded]; // macOS's imageViewLayer may not equal to self.layer. But `[super setImage:]` will impliedly mark it needsDisplay. We call `[self.layer displayIfNeeded]` to immediately refresh the imageViewLayer to avoid flashing
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -312,13 +306,6 @@ static NSUInteger SDDeviceFreeMemory() {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if SD_MAC
|
|
||||||
- (CALayer *)imageViewLayer {
|
|
||||||
NSView *imageView = objc_getAssociatedObject(self, NSSelectorFromString(@"_imageView"));
|
|
||||||
return imageView.layer;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#pragma mark - Life Cycle
|
#pragma mark - Life Cycle
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc
|
||||||
|
@ -681,6 +668,18 @@ static NSUInteger SDDeviceFreeMemory() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SD_MAC
|
#if SD_MAC
|
||||||
|
// Layer-backed NSImageView optionally optimize to use a subview to do actual layer rendering.
|
||||||
|
// When the optimization is turned on, it calls `updateLayer` instead of `displayLayer:` to update subview's layer.
|
||||||
|
// When the optimization it turned off, this return nil and calls `displayLayer:` directly.
|
||||||
|
- (CALayer *)imageViewLayer {
|
||||||
|
NSView *imageView = imageView = objc_getAssociatedObject(self, NSSelectorFromString(@"_imageView"));
|
||||||
|
if (!imageView) {
|
||||||
|
// macOS 10.14
|
||||||
|
imageView = objc_getAssociatedObject(self, NSSelectorFromString(@"_imageSubview"));
|
||||||
|
}
|
||||||
|
return imageView.layer;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)updateLayer
|
- (void)updateLayer
|
||||||
{
|
{
|
||||||
if (_currentFrame) {
|
if (_currentFrame) {
|
||||||
|
|
Loading…
Reference in New Issue