YYTextAsyncLayer
崩潰問(wèn)題修復(fù)
// 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);
YBImageBrowser
崩潰問(wèn)題修復(fù)
UIImage *YBIBSnapshotView(UIView *view) {
// UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, [UIScreen mainScreen].scale);
// [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO];
// UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
// UIGraphicsEndImageContext();
CGSize size = view.bounds.size;
UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];
format.scale = [UIScreen mainScreen].scale;
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:size format:format];
UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
}];
return image;
}