iOS:fix iOS 14 cannot display image

This commit is contained in:
pengfei.zhou 2020-09-18 16:58:19 +08:00 committed by osborn
parent b9b0ce22b2
commit 171e96d0b5

View File

@ -30,6 +30,17 @@ @interface DoricImageView : YYAnimatedImageView
@end @end
@implementation DoricImageView @implementation DoricImageView
- (void)displayLayer:(CALayer *)layer {
if (@available(iOS 14.0, *)) {
if (self.isAnimating) {
[super displayLayer:layer];
} else {
layer.contents = (__bridge id) self.image.CGImage;
};
} else {
[super displayLayer:layer];
}
}
@end @end
@interface DoricImageNode () @interface DoricImageNode ()
@ -85,7 +96,7 @@ - (UIImage *)currentPlaceHolderImage {
if (self.placeHolderImage) { if (self.placeHolderImage) {
return [UIImage imageNamed:self.placeHolderImage]; return [UIImage imageNamed:self.placeHolderImage];
} }
if (self.placeHolderImageBase64) { if (self.placeHolderImageBase64) {
NSString *base64 = self.placeHolderImageBase64; NSString *base64 = self.placeHolderImageBase64;
if (YES == [base64 hasPrefix:@"data:image"]) { if (YES == [base64 hasPrefix:@"data:image"]) {
@ -96,7 +107,7 @@ - (UIImage *)currentPlaceHolderImage {
YYImage *image = [YYImage imageWithData:imageData scale:self.imageScale]; YYImage *image = [YYImage imageWithData:imageData scale:self.imageScale];
return image; return image;
} }
if (self.placeHolderColor) { if (self.placeHolderColor) {
UIColor *color = DoricColor(self.placeHolderColor); UIColor *color = DoricColor(self.placeHolderColor);
CGRect rect = CGRectMake(0, 0, 1, 1); CGRect rect = CGRectMake(0, 0, 1, 1);
@ -118,7 +129,7 @@ - (UIImage *)currentErrorImage {
if (self.errorImage) { if (self.errorImage) {
return [UIImage imageNamed:self.errorImage]; return [UIImage imageNamed:self.errorImage];
} }
if (self.errorImageBase64) { if (self.errorImageBase64) {
NSString *base64 = self.errorImageBase64; NSString *base64 = self.errorImageBase64;
if (YES == [base64 hasPrefix:@"data:image"]) { if (YES == [base64 hasPrefix:@"data:image"]) {
@ -129,7 +140,7 @@ - (UIImage *)currentErrorImage {
YYImage *image = [YYImage imageWithData:imageData scale:self.imageScale]; YYImage *image = [YYImage imageWithData:imageData scale:self.imageScale];
return image; return image;
} }
if (self.errorColor) { if (self.errorColor) {
UIColor *color = DoricColor(self.errorColor); UIColor *color = DoricColor(self.errorColor);
CGRect rect = CGRectMake(0, 0, 1, 1); CGRect rect = CGRectMake(0, 0, 1, 1);
@ -276,7 +287,7 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
} }
} }
} else if ([@"stretchInset" isEqualToString:name]) { } else if ([@"stretchInset" isEqualToString:name]) {
self.stretchInsetDic = (NSDictionary *)prop; self.stretchInsetDic = (NSDictionary *) prop;
} else if ([@"imageScale" isEqualToString:name]) { } else if ([@"imageScale" isEqualToString:name]) {
//Do not need set //Do not need set
} else { } else {
@ -291,7 +302,7 @@ - (void)afterBlended:(NSDictionary *)props {
CGFloat right = [self.stretchInsetDic[@"right"] floatValue]; CGFloat right = [self.stretchInsetDic[@"right"] floatValue];
CGFloat bottom = [self.stretchInsetDic[@"bottom"] floatValue]; CGFloat bottom = [self.stretchInsetDic[@"bottom"] floatValue];
CGFloat scale = self.imageScale; CGFloat scale = self.imageScale;
UIImage *result = [self.view.image resizableImageWithCapInsets:UIEdgeInsetsMake(top/scale, left/scale, bottom/scale, right/scale) resizingMode:UIImageResizingModeStretch]; UIImage *result = [self.view.image resizableImageWithCapInsets:UIEdgeInsetsMake(top / scale, left / scale, bottom / scale, right / scale) resizingMode:UIImageResizingModeStretch];
self.view.image = result; self.view.image = result;
} }
} }