Skip to content

Commit efcf386

Browse files
committed
fix iOS 17 crash: ibireme#1006
1 parent 7bd2aa4 commit efcf386

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

YYText/Utility/YYTextAsyncLayer.m

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -200,28 +200,33 @@ - (void)_displayAsync:(BOOL)async {
200200
} else {
201201
[_sentinel increase];
202202
if (task.willDisplay) task.willDisplay(self);
203-
UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.opaque, self.contentsScale);
204-
CGContextRef context = UIGraphicsGetCurrentContext();
205-
if (self.opaque && context) {
206-
CGSize size = self.bounds.size;
207-
size.width *= self.contentsScale;
208-
size.height *= self.contentsScale;
209-
CGContextSaveGState(context); {
210-
if (!self.backgroundColor || CGColorGetAlpha(self.backgroundColor) < 1) {
211-
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
212-
CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height));
213-
CGContextFillPath(context);
214-
}
215-
if (self.backgroundColor) {
216-
CGContextSetFillColorWithColor(context, self.backgroundColor);
217-
CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height));
218-
CGContextFillPath(context);
219-
}
220-
} CGContextRestoreGState(context);
221-
}
222-
task.display(context, self.bounds.size, ^{return NO;});
223-
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
224-
UIGraphicsEndImageContext();
203+
UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];
204+
format.opaque = self.opaque;
205+
format.scale = self.contentsScale;
206+
207+
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:self.bounds.size format:format];
208+
UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
209+
CGContextRef context = rendererContext.CGContext;
210+
if (self.opaque) {
211+
CGSize size = self.bounds.size;
212+
size.width *= self.contentsScale;
213+
size.height *= self.contentsScale;
214+
CGContextSaveGState(context); {
215+
if (!self.backgroundColor || CGColorGetAlpha(self.backgroundColor) < 1) {
216+
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
217+
CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height));
218+
CGContextFillPath(context);
219+
}
220+
if (self.backgroundColor) {
221+
CGContextSetFillColorWithColor(context, self.backgroundColor);
222+
CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height));
223+
CGContextFillPath(context);
224+
}
225+
} CGContextRestoreGState(context);
226+
}
227+
task.display(context, self.bounds.size, ^{return NO;});
228+
}];
229+
225230
self.contents = (__bridge id)(image.CGImage);
226231
if (task.didDisplay) task.didDisplay(self, YES);
227232
}

0 commit comments

Comments
 (0)