iOS 17.0 YYText 瓦解处置惩罚

打印 上一主题 下一主题

主题 1001|帖子 1001|积分 3003

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
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

  1. UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.opaque, self.contentsScale);
  2. CGContextRef context = UIGraphicsGetCurrentContext();
  3. if (self.opaque) {
  4. CGSize size = self.bounds.size;
  5. size.width *= self.contentsScale;
  6. size.height *= self.contentsScale;
  7. CGContextSaveGState(context); {
  8. if (!self.backgroundColor || CGColorGetAlpha(self.backgroundColor) < 1) {
  9. CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
  10. CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height));
  11. CGContextFillPath(context);
  12. }
  13. if (self.backgroundColor) {
  14. CGContextSetFillColorWithColor(context, self.backgroundColor);
  15. CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height));
  16. CGContextFillPath(context);
  17. }
  18. } CGContextRestoreGState(context);
  19. }
  20. task.display(context, self.bounds.size, ^{return NO;});
  21. UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  22. UIGraphicsEndImageContext();
  23. self.contents = (__bridge id)(image.CGImage);
复制代码
替换为:
  1.   UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];
  2.         format.opaque = self.opaque;
  3.         format.scale = self.contentsScale;
  4.         UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:self.bounds.size format:format];
  5.         UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
  6.             CGContextRef context = rendererContext.CGContext;
  7.             if (self.opaque) {
  8.                 CGSize size = self.bounds.size;
  9.                 size.width *= self.contentsScale;
  10.                 size.height *= self.contentsScale;
  11.                 CGContextSaveGState(context); {
  12.                     if (!self.backgroundColor || CGColorGetAlpha(self.backgroundColor) < 1) {
  13.                         CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
  14.                         CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height));
  15.                         CGContextFillPath(context);
  16.                     }
  17.                     if (self.backgroundColor) {
  18.                         CGContextSetFillColorWithColor(context, self.backgroundColor);
  19.                         CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height));
  20.                         CGContextFillPath(context);
  21.                     }
  22.                 } CGContextRestoreGState(context);
  23.             }
  24.             task.display(context, self.bounds.size, ^{return NO;});
  25.         }];
  26.         self.contents = (__bridge id)(image.CGImage);
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

半亩花草

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表