马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
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
将
- 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);
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |