iOS 17.0 YYText UIGraphicsBeginImageContextWithOptions 崩溃处理

慈云数据 2024-05-13 技术支持 84 0

在iOS17上,YYText会报以下错误:

iOS 17.0 YYText UIGraphicsBeginImageContextWithOptions 崩溃处理
(图片来源网络,侵删)

UIGraphicsBegiNimageContext() failed to allocate CGBitampContext: size={0, 0}, scale=3.000000, bitmAPInfo=0x2002. Use UIGraphicsImageRenderer to avoid this assert.

解决方法如下:

iOS 17.0 YYText UIGraphicsBeginImageContextWithOptions 崩溃处理
(图片来源网络,侵删)

在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) 
                
                
                
微信扫一扫加客服

微信扫一扫加客服

点击启动AI问答
Draggable Icon