Change our SDScaledImageForKey to use scale on macOS

This commit is contained in:
DreamPiggy 2018-01-21 23:26:47 +08:00
parent 9e48da8a8a
commit d4daca3c12
1 changed files with 13 additions and 6 deletions

View File

@ -23,9 +23,7 @@ inline UIImage *SDScaledImageForKey(NSString * _Nullable key, UIImage * _Nullabl
return nil; return nil;
} }
#if SD_MAC #if SD_UIKIT || SD_WATCH
return image;
#elif SD_UIKIT || SD_WATCH
if ((image.images).count > 0) { if ((image.images).count > 0) {
NSMutableArray<UIImage *> *scaledImages = [NSMutableArray array]; NSMutableArray<UIImage *> *scaledImages = [NSMutableArray array];
@ -39,10 +37,13 @@ inline UIImage *SDScaledImageForKey(NSString * _Nullable key, UIImage * _Nullabl
} }
return animatedImage; return animatedImage;
} else { } else {
#endif
#if SD_WATCH #if SD_WATCH
if ([[WKInterfaceDevice currentDevice] respondsToSelector:@selector(screenScale)]) { if ([[WKInterfaceDevice currentDevice] respondsToSelector:@selector(screenScale)]) {
#elif SD_UIKIT #elif SD_UIKIT
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) { if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
#elif SD_MAC
if ([[NSScreen mainScreen] respondsToSelector:@selector(backingScaleFactor)]) {
#endif #endif
CGFloat scale = 1; CGFloat scale = 1;
if (key.length >= 8) { if (key.length >= 8) {
@ -56,11 +57,17 @@ inline UIImage *SDScaledImageForKey(NSString * _Nullable key, UIImage * _Nullabl
scale = 3.0; scale = 3.0;
} }
} }
if (scale > 1) {
#if SD_UIKIT || SD_WATCH
UIImage *scaledImage = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:image.imageOrientation]; UIImage *scaledImage = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:image.imageOrientation];
#else
UIImage *scaledImage = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale];
#endif
image = scaledImage; image = scaledImage;
} }
}
return image; return image;
#if SD_UIKIT || SD_WATCH
} }
#endif #endif
} }