You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
大佬,我们这边使用了您的YYText,发现在iOS 17上运行会崩溃,触发了系统的断言:
UIGraphicsBeginImageContext() failed to allocate CGBitampContext: size={382, 0}, scale=3.000000, bitmapInfo=0x2002. Use UIGraphicsImageRenderer to avoid this assert.
Activity
w1090485608 commentedon Jun 15, 2023
将
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;
CodeSlaveZhang commentedon Sep 26, 2023
如果不想像上面一样处理
可以在
这个函数里面添加
if (self.bounds.size.width<=0 || self.bounds.size.height<=0) {
self.contents = nil;
return;
}
bugfix: ibireme#984 UIGraphicsBeginImageContext() failed to allocate …
bugfix: ibireme#984 UIGraphicsBeginImageContext() failed to allocate …
bugfix: ibireme#984 UIGraphicsBeginImageContext() failed to allocate …
bugfix: ibireme#984 UIGraphicsBeginImageContext() failed to allocate …
bugfix: ibireme#984 UIGraphicsBeginImageContext() failed to allocate …
fix issue on ibireme#984
wanghaolyj commentedon Oct 25, 2023
@implementation YYTextAsyncLayer(Hook)
Method a = class_getInstanceMethod(self, @selector(display));
Method b = class_getInstanceMethod(self, @selector(swizzing_display));
method_exchangeImplementations(a, b);
}
//通过变量名称获取类中的实例成员变量
if (self.bounds.size.width<=0 || self.bounds.size.height<=0) {
self.contents = nil;
return;
} else {
[self swizzing_display];
}
}
@EnD
It's better to do this
ZackDT commentedon Nov 2, 2023
Swift的话,采用上面一样的hook方法,在appdelegate方法中调用 YYTextAsyncLayer.swizzleDisplay
`
import YYText
/// 避免iOS17的崩溃
extension YYTextAsyncLayer {
}
`
bugfix: ibireme#984 UIGraphicsBeginImageContext() failed
lizhi0123 commentedon Nov 29, 2023
I do not want to change code in pods. so I create two classe. PPYYLabel, PPYYTextAsyncLayer . user PPYYLabel replace YYLabel
zhoumingwu commentedon Dec 1, 2023
It seems like the master has retired from the scene for many years. It's unlikely that he will make a comeback again
NubiaYin commentedon Dec 20, 2023
这个API还能继续用,只不过当layer的width或height 为0时会触发断言,否则不会。
这个场景在使用AutoLayout时比较常见。
MonicaZhou commentedon May 6, 2024
最低支持iOS9的代码,得用这个~