美文网首页
YYText iOS17 崩溃处理

YYText iOS17 崩溃处理

作者: 古方月 | 来源:发表于2024-02-27 11:43 被阅读0次

YYText 在iOS17的系统上运行可能会崩溃,
经查询发现api弃用 UIGraphicsBeginImageContext (deprecated)

处理方案: YYTextAsyncLayer.m 更新
原文件

UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.opaque, self.contentsScale);
CGContextRef context = UIGraphicsGetCurrentContext();
if (self.opaque) {
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();
self.contents = (__bridge id)(image.CGImage);

更新后

  UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];
        format.opaque = self.opaque;
        format.scale = self.contentsScale;

        UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:self.bounds.size format:format];
        UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
            CGContextRef context = rendererContext.CGContext;
            if (self.opaque) {
                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;});
        }];

        self.contents = (__bridge id)(image.CGImage);

相关文章

  • YYText使用篇(十一)

    版本记录 前言 YYText是一个专门处理文字的框架,有了它处理文字变得非常方便,这一篇我继续介绍YYText的使...

  • YYText使用篇(七)

    版本记录 前言 YYText是一个专门处理文字的框架,有了它处理文字变得非常方便,这一篇我继续介绍YYText的使...

  • YYText使用篇(五)

    版本记录 前言 YYText是一个专门处理文字的框架,有了它处理文字变得非常方便,这一篇我继续介绍YYText的使...

  • YYText使用篇(四)

    版本记录 前言 YYText是一个专门处理文字的框架,有了它处理文字变得非常方便,这一篇我继续介绍YYText的使...

  • YYText使用篇(二)

    版本记录 前言 YYText是一个专门处理文字的框架,有了它处理文字变得非常方便,这一篇我继续介绍YYText的使...

  • YYText源码分析

    YYText 简单介绍 YYText 是YYKit中的一个富文本显示,编辑组件,拥有YYLabel,YYText...

  • YYKit之YYText、YYLabel使用总结(更新)

    1.索引 YYText YYLabel 更新 YYText IQKeyboardManager支持 布局问题 如果...

  • RN-逻辑崩溃处理:react-native-exception

    和 componentDidCatch 配合使用,页面崩溃处理 + 逻辑崩溃处理,防止大部分的崩溃~

  • YYText使用

    NSMutableString + YYText实例YYText+add tag制作文字tag 文字附加attac...

  • YYText 源码解析

    YYText [%5Bhttps://github.com/ibireme/YYText%5D(https://g...

网友评论

      本文标题:YYText iOS17 崩溃处理

      本文链接:https://www.haomeiwen.com/subject/frbtzdtx.html