From 2eb854f50263b6b19608a04dc7a2451fec44bec5 Mon Sep 17 00:00:00 2001 From: mengzc <1361991812@qq.com> Date: Sat, 12 Oct 2024 14:10:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9iOS17.0=E4=BB=A5=E4=B8=8AUIGr?= =?UTF-8?q?aphicsBeginImageContextWithOptions=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YBImageBrowser/Helper/YBIBUtilities.m | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/YBImageBrowser/Helper/YBIBUtilities.m b/YBImageBrowser/Helper/YBIBUtilities.m index ba074f8..4e9b1ac 100644 --- a/YBImageBrowser/Helper/YBIBUtilities.m +++ b/YBImageBrowser/Helper/YBIBUtilities.m @@ -91,11 +91,27 @@ CGFloat YBIBSafeAreaBottomHeight(void) { } UIImage *YBIBSnapshotView(UIView *view) { - UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, [UIScreen mainScreen].scale); - [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO]; - UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); - UIGraphicsEndImageContext(); - return image; + // UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, [UIScreen mainScreen].scale); + // [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO]; + // UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); + // UIGraphicsEndImageContext(); + // return image; + 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; + } } UIEdgeInsets YBIBPaddingByBrowserOrientation(UIDeviceOrientation orientation) {