-
Notifications
You must be signed in to change notification settings - Fork 476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ios17点击查看图片崩溃 #356
Comments
建议把这个方法改成下面这样 UIImage *YBIBSnapshotView(UIView *view) {
if (@available(iOS 10.0, *)) {
UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];
format.scale = [UIScreen mainScreen].scale;
format.opaque = YES;
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:view.bounds.size format:format];
UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull context) {
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO];
}];
return image;
} else {
UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, [UIScreen mainScreen].scale);
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
} |
有用
👍 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
调用方法
YBIBImageData *ybData = [YBIBImageData new];
ybData.imageURL = [NSURL URLWithString:urlString];
ybData.projectiveView = nil;
YBImageBrowser *browser = [YBImageBrowser new];
browser.dataSourceArray = @[ybData];
browser.currentPage = 0;
[browser show];
崩溃的地方
UIImage *YBIBSnapshotView(UIView *view) {
UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, [UIScreen mainScreen].scale);
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
建议:
UIImage *YBIBSnapshotView(UIView *view) {
//这里加上
if(![view isKindOfClass:UIView.class] || view.bounds.size.width<=1||view.bounds.size.height<=1){
return UIImage.new;
}
UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, [UIScreen mainScreen].scale);
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
Environment
The text was updated successfully, but these errors were encountered: