当前位置: 首页 > news >正文

iOS 17.0 YYText 崩溃处理

YYText,发现在iOS 17上运行会崩溃,触发了系统的断言:
UIGraphicsBeginImageContext() failed to allocate CGBitampContext: size={382, 0}, scale=3.000000, bitmapInfo=0x2002. Use UIGraphicsImageRenderer to avoid this assert.

查了下 api,发现UIGraphicsBeginImageContext在iOS 17上已经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);
http://www.lryc.cn/news/240138.html

相关文章:

  • 微信小程序面试题【100道】
  • 【nlp】2.8 注意力机制拓展
  • mysql 存储引擎ROWS与实际行数不一致
  • 软考小记-软件工程
  • 【开源】基于Vue和SpringBoot的创意工坊双创管理系统
  • COBOL排序问题
  • 数字化转型过程中面临最大的问题是什么?如何借助数字化工具实现快速转型?
  • 视频剪辑有妙招:批量置入封面,轻松提升视频效果
  • Java查询多条数据放入word模板 多个word文件处理成zip压缩包并在前端下载.zip文件
  • PC8223(CC/CV控制)高耐压输入5V/3.4A同步降压电路内建补偿带恒流恒压输出
  • 【webrtc】ModuleRtpRtcpImpl2: RtpRtcp DEPRECATED_Create 废弃了
  • 八股文面试day5
  • 数据处理生产环境_获取当前日期的前一天日期
  • 5.过滤敏感词 + 发布帖子 + 帖子详情
  • 大数据基础设施搭建 - Flume
  • 华为OD机试 - 找朋友(Java 2023 B卷 100分)
  • ESP32 MicroPython 颜色及二维码识别⑫
  • 数据结构与算法编程题15
  • 基于Mapmost Alpha工具快速搭建3D场景可视化大屏
  • OpenAI再次与Sam Altman谈判;ChatGPT Voice正式上线
  • 技术是增长关键驱动!传音控股新专利亮相,看未来手机趋势
  • C# - Opencv应用(2) 之矩阵Mat使用[矩阵创建、图像显示、像素读取与赋值]
  • 执行npm的时候报权限问题的解决方案
  • 【实用】PPT没几页内存很大怎么解决
  • 【Docker】从零开始:8.Docker命令:Commit提交命令
  • 【深度学习】神经网络术语:Epoch、Batch Size和迭代
  • 谈谈你对mvc和mvvm的理解
  • C语言每日一题(35)有效的括号
  • 【DevOps】Git 图文详解(七):标签管理
  • BootStrap【表格二、基础表单、被支持的控件、表单状态】(二)-全面详解(学习总结---从入门到深化)