iOS 17.0 YYText UIGraphicsBeginImageContextWithOptions 崩溃处理
在iOS17上,YYText会报以下错误:
(图片来源网络,侵删)
UIGraphicsBeginImageContext() failed to allocate CGBitampContext: size={0, 0}, scale=3.000000, bitmapInfo=0x2002. Use UIGraphicsImageRenderer to avoid this assert.
解决方法如下:
在YYTextAsyncLayer.m文件中,_displayAsync:(BOOL)async 方法中。
原代码:
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)修复后的代码:
(图片来源网络,侵删)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)
文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。
还没有评论,来说两句吧...