• 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);
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25

    替换为:

      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);
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
  • 相关阅读:
    RHCSA常用命令总结
    centos7编译安装qt4遇到的问题
    C# 连接mysql 数据库
    常用LaTeX命令
    关于面试,95%会问到的Java面试题(高级部分)
    SOHO帮客户找新品,如何拿到最优价?要不要选择大型机械类产品?
    协程(三)——协程在并发中的优势
    这就是艺术「GitHub 热点速览 v.22.25」
    上海-华为合作伙伴之夜:创新领导力 | 竹云荣膺“华为全球杰出行业解决方案合作伙伴奖”
    短视频运营小技巧,互动引流很重要,内容质量也不能忘
  • 原文地址:https://blog.csdn.net/weixin_42050662/article/details/134524136