Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

适配iOS17 #604

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
1 change: 1 addition & 0 deletions YYKit/Base/Quartz/CALayer+YYAdd.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@implementation CALayer (YYAdd)

- (UIImage *)snapshotImage {
if (self.bounds.size.width <= 0 || self.bounds.size.height <= 0) return nil;
UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.opaque, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
[self renderInContext:context];
Expand Down
4 changes: 4 additions & 0 deletions YYKit/Base/UIKit/UIImage+YYAdd.m
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ + (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size {

+ (UIImage *)imageWithSize:(CGSize)size drawBlock:(void (^)(CGContextRef context))drawBlock {
if (!drawBlock) return nil;
if (size.width <= 0 || size.height <= 0) return nil;
UIGraphicsBeginImageContextWithOptions(size, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
if (!context) return nil;
Expand Down Expand Up @@ -371,6 +372,7 @@ - (UIImage *)imageByRoundCornerRadius:(CGFloat)radius
borderWidth:(CGFloat)borderWidth
borderColor:(UIColor *)borderColor
borderLineJoin:(CGLineJoin)borderLineJoin {
if (self.size.width <= 0 || self.size.height <= 0) return nil;

if (corners != UIRectCornerAllCorners) {
UIRectCorner tmp = 0;
Expand Down Expand Up @@ -500,6 +502,7 @@ - (UIImage *)imageByFlipHorizontal {
}

- (UIImage *)imageByTintColor:(UIColor *)color {
if (self.size.width <= 0 || self.size.height <= 0) return nil;
UIGraphicsBeginImageContextWithOptions(self.size, NO, self.scale);
CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
[color set];
Expand Down Expand Up @@ -714,6 +717,7 @@ - (UIImage *)_yy_mergeImageRef:(CGImageRef)effectCGImage
tintBlendMode:(CGBlendMode)tintBlendMode
maskImage:(UIImage *)maskImage
opaque:(BOOL)opaque {
if (self.size.width <= 0 || self.size.height <= 0) return nil;
BOOL hasTint = tintColor != nil && CGColorGetAlpha(tintColor.CGColor) > __FLT_EPSILON__;
BOOL hasMask = maskImage != nil;
CGSize size = self.size;
Expand Down
2 changes: 2 additions & 0 deletions YYKit/Base/UIKit/UIView+YYAdd.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@implementation UIView (YYAdd)

- (UIImage *)snapshotImage {
if (self.bounds.size.width <= 0 || self.bounds.size.height <= 0) return nil;
UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.opaque, 0);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *snap = UIGraphicsGetImageFromCurrentImageContext();
Expand All @@ -30,6 +31,7 @@ - (UIImage *)snapshotImageAfterScreenUpdates:(BOOL)afterUpdates {
if (![self respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]) {
return [self snapshotImage];
}
if (self.bounds.size.width <= 0 || self.bounds.size.height <= 0) return nil;
UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.opaque, 0);
[self drawViewHierarchyInRect:self.bounds afterScreenUpdates:afterUpdates];
UIImage *snap = UIGraphicsGetImageFromCurrentImageContext();
Expand Down
98 changes: 49 additions & 49 deletions YYKit/Utility/YYAsyncLayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -145,33 +145,32 @@ - (void)_displayAsync:(BOOL)async {
CGColorRelease(backgroundColor);
return;
}
UIGraphicsBeginImageContextWithOptions(size, opaque, scale);
CGContextRef context = UIGraphicsGetCurrentContext();
if (opaque && context) {
CGContextSaveGState(context); {
if (!backgroundColor || CGColorGetAlpha(backgroundColor) < 1) {
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextAddRect(context, CGRectMake(0, 0, size.width * scale, size.height * scale));
CGContextFillPath(context);
}
if (backgroundColor) {
CGContextSetFillColorWithColor(context, backgroundColor);
CGContextAddRect(context, CGRectMake(0, 0, size.width * scale, size.height * scale));
CGContextFillPath(context);
}
} CGContextRestoreGState(context);
CGColorRelease(backgroundColor);
}
task.display(context, size, isCancelled);
if (isCancelled()) {
UIGraphicsEndImageContext();
dispatch_async(dispatch_get_main_queue(), ^{
if (task.didDisplay) task.didDisplay(self, NO);
});
return;
}
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:size];
UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull context) {
if (opaque) {
CGContextSaveGState(context.CGContext); {
if (!backgroundColor || CGColorGetAlpha(backgroundColor) < 1) {
CGContextSetFillColorWithColor(context.CGContext, [UIColor whiteColor].CGColor);
CGContextAddRect(context.CGContext, CGRectMake(0, 0, size.width * scale, size.height * scale));
CGContextFillPath(context.CGContext);
}
if (backgroundColor) {
CGContextSetFillColorWithColor(context.CGContext, backgroundColor);
CGContextAddRect(context.CGContext, CGRectMake(0, 0, size.width * scale, size.height * scale));
CGContextFillPath(context.CGContext);
}
} CGContextRestoreGState(context.CGContext);
CGColorRelease(backgroundColor);
}
task.display(context.CGContext, size, isCancelled);
if (isCancelled()) {
dispatch_async(dispatch_get_main_queue(), ^{
if (task.didDisplay) task.didDisplay(self, NO);
});
return;
}
}];
if (isCancelled()) {
dispatch_async(dispatch_get_main_queue(), ^{
if (task.didDisplay) task.didDisplay(self, NO);
Expand All @@ -190,28 +189,29 @@ - (void)_displayAsync:(BOOL)async {
} else {
[_sentinel increase];
if (task.willDisplay) task.willDisplay(self);
UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.opaque, self.contentsScale);
CGContextRef context = UIGraphicsGetCurrentContext();
if (self.opaque && context) {
CGSize size = self.bounds.size;
size.width *= self.contentsScale;
size.height *= self.contentsScale;
CGContextSaveGState(context); {
if (!self.backgroundColor || CGColorGetAlpha(self.backgroundColor) < 1) {
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height));
CGContextFillPath(context);
}
if (self.backgroundColor) {
CGContextSetFillColorWithColor(context, self.backgroundColor);
CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height));
CGContextFillPath(context);
}
} CGContextRestoreGState(context);
}
task.display(context, self.bounds.size, ^{return NO;});
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGSize size = self.bounds.size;
BOOL opaque = self.opaque;
CGFloat scale = self.contentsScale;
CGColorRef backgroundColor = (opaque && self.backgroundColor) ? CGColorRetain(self.backgroundColor) : NULL;
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:size];
UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull context) {
if (opaque) {
CGContextSaveGState(context.CGContext); {
if (!backgroundColor || CGColorGetAlpha(backgroundColor) < 1) {
CGContextSetFillColorWithColor(context.CGContext, [UIColor whiteColor].CGColor);
CGContextAddRect(context.CGContext, CGRectMake(0, 0, size.width * scale, size.height * scale));
CGContextFillPath(context.CGContext);
}
if (backgroundColor) {
CGContextSetFillColorWithColor(context.CGContext, backgroundColor);
CGContextAddRect(context.CGContext, CGRectMake(0, 0, size.width * scale, size.height * scale));
CGContextFillPath(context.CGContext);
}
} CGContextRestoreGState(context.CGContext);
CGColorRelease(backgroundColor);
}
task.display((__bridge CGContextRef _Nonnull)(context), self.bounds.size, ^{return NO;});
}];
self.contents = (__bridge id)(image.CGImage);
if (task.didDisplay) task.didDisplay(self, YES);
}
Expand Down