YYText iOS17兼容问题
•
移动开发
使用YYText ,1.0.7在iOS17会遇到如下崩溃

主要原因是UIGraphicsBeginImageContext中的asert引发,而改接口早就标记为API_TO_BE_DEPRECATED,建议使用UIGraphicsImageRenderer替换。
由于YYText早已没有维护,于是fork了一个自己的git进行修正,主要修正逻辑在textAsynLayer

替换为
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;
}
}];
github地址
具体可参见git@github.com:iamanthonyzhu/YYTextAsynLayer.git
本文来自网络,不代表协通编程立场,如若转载,请注明出处:https://net2asp.com/7e0d1ef2a9.html
