{"id":4905,"date":"2022-01-16T19:51:31","date_gmt":"2022-01-16T11:51:31","guid":{"rendered":"http:\/\/123.57.164.21\/?p=4905"},"modified":"2022-01-16T19:51:31","modified_gmt":"2022-01-16T11:51:31","slug":"sheetkit-swiftui-%e6%a8%a1%e6%80%81%e8%a7%86%e5%9b%be%e6%89%a9%e5%b1%95%e5%ba%93","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=4905","title":{"rendered":"SheetKit\u2014\u2014SwiftUI \u6a21\u6001\u89c6\u56fe\u6269\u5c55\u5e93"},"content":{"rendered":"\n<h5 class=\"wp-block-heading\">SheetKit \u662f\u4ec0\u4e48<\/h5>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><a href=\"https:\/\/github.com\/fatbobman\/SheetKit\" target=\"_blank\" rel=\"noreferrer noopener\">SheetKit<\/a> \u662f\u4e00\u4e2a SwiftUI \u6a21\u6001\u89c6\u56fe\u7684\u6269\u5c55\u5e93\u3002\u63d0\u4f9b\u4e86\u6570\u4e2a\u7528\u4e8e\u6a21\u6001\u89c6\u56fe\u7684\u4fbf\u6377\u5c55\u793a\u3001\u53d6\u6d88\u65b9\u6cd5\uff0c\u4ee5\u53ca\u51e0\u4e2a\u7528\u4e8e\u6a21\u6001\u89c6\u56fe\u7684 View Extension\u3002<\/p>\n\n\n\n<p>\u5f00\u53d1 SheetKit \u7684\u4e3b\u8981\u539f\u56e0\uff1a<\/p>\n\n\n\n<ul><li>\u4fbf\u4e8e Deep link \u7684\u8c03\u7528<\/li><\/ul>\n\n\n\n<p>SwiftUI \u63d0\u4f9b\u4e86<code>onOpenURL<\/code>\u65b9\u6cd5\u8ba9\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u975e\u5e38\u8f7b\u677e\u7684\u54cd\u5e94 Deep Link\u3002\u4f46\u5728\u5b9e\u9645\u4f7f\u7528\u4e2d\uff0c\u60c5\u51b5\u5e76\u4e0d\u5982\u9884\u671f\u3002\u4e3b\u8981\u56e0\u4e3a SwiftUI \u4e2d\u91cd\u8981\u7684\u89c6\u56fe\u5c55\u793a\u6a21\u5f0f\uff1aNavigationView\u3001Sheet \u7b49\u90fd\u6ca1\u6709\u8fc5\u6377\u3001\u7b80\u4fbf\u7684\u91cd\u7f6e\u80fd\u529b\u3002\u5f88\u96be\u901a\u8fc7\u4e00\u4e24\u53e5\u4ee3\u7801\u5c06\u5e94\u7528\u7a0b\u5e8f\u7acb\u5373\u8bbe\u7f6e\u6210\u6211\u4eec\u60f3\u8981\u7684\u89c6\u56fe\u72b6\u6001\u3002<\/p>\n\n\n\n<ul><li>\u6a21\u6001\u89c6\u56fe\u7684\u96c6\u4e2d\u7ba1\u7406<\/li><\/ul>\n\n\n\n<p>SwiftUI \u901a\u5e38\u91c7\u7528<code>.sheet<\/code>\u6765\u521b\u5efa\u6a21\u6001\u89c6\u56fe\uff0c\u5bf9\u4e8e\u7b80\u5355\u7684\u5e94\u7528\u6765\u8bf4\uff0c\u8fd9\u79cd\u5f62\u5f0f\u975e\u5e38\u76f4\u89c2\uff0c\u4f46\u5982\u679c\u5e94\u7528\u7a0b\u5e8f\u7684\u903b\u8f91\u6bd4\u8f83\u590d\u6742\u3001\u9700\u8981\u7684\u6a21\u6001\u89c6\u56fe\u4f17\u591a\uff0c\u5219\u4e0a\u8ff0\u65b9\u5f0f\u5c31\u4f1a\u8ba9\u4ee3\u7801\u663e\u5f97\u5341\u5206\u6df7\u4e71\uff0c\u4e0d\u6613\u6574\u7406\u3002\u56e0\u6b64\uff0c\u5728\u6b64\u79cd\u60c5\u51b5\u4e0b\uff0c\u901a\u5e38\u6211\u4eec\u4f1a\u5c06\u6240\u6709\u7684\u6a21\u6001\u89c6\u56fe\u96c6\u4e2d\u7ba1\u7406\u8d77\u6765\uff0c\u7edf\u4e00\u8c03\u7528\u3002\u8bf7\u53c2\u9605\u6211\u4e4b\u524d\u7684\u6587\u7ae0\u2014\u2014<a href=\"https:\/\/www.fatbobman.com\/posts\/swiftui-multiSheet\/\">\u5728 SwiftUI \u4e2d\uff0c\u6839\u636e\u9700\u6c42\u5f39\u51fa\u4e0d\u540c\u7684 Sheet<\/a>\u3002<\/p>\n\n\n\n<ul><li>\u65b0\u7684\u534a\u9ad8\u6a21\u6001\u89c6\u56fe<\/li><\/ul>\n\n\n\n<p>\u5728 WWDC 2021 \u4e2d\uff0c\u82f9\u679c\u4e3a\u5927\u5bb6\u5e26\u6765\u4e86\u671f\u5f85\u5df2\u4e45\u7684\u534a\u9ad8\u6a21\u6001\u89c6\u56fe\u3002\u6216\u8bb8\u63a8\u51fa\u7684\u6bd4\u8f83\u4ed3\u4fc3\uff0c\u8fd9\u79cd\u5f88\u53d7\u6b22\u8fce\u7684\u4ea4\u4e92\u65b9\u5f0f\u5e76\u6ca1\u6709\u63d0\u4f9b SwiftUI \u7248\u672c\uff0c\u4ec5\u652f\u6301 UIKit\u3002SheetKit \u6682\u65f6\u5f25\u8865\u4e86\u8fd9\u4e2a\u9057\u61be\u3002\u65e0\u8bba sheet\u3001fullScreenCover \u8fd8\u662f bottomSheet\uff08\u534a\u9ad8\u6a21\u6001\u89c6\u56fe\uff09\u90fd\u5f97\u5230\u5145\u5206\u7684\u652f\u6301\u548c\u7edf\u4e00\u7684\u7ba1\u7406\u3002<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">\u7cfb\u7edf\u8981\u6c42<\/h5>\n\n\n\n<ul><li>iOS 15<\/li><li>Swift 5.5<\/li><li>XCode 13.0 +<\/li><\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u53ea\u9700\u5265\u79bb\u6a21\u6001\u89c6\u56fe\u7684\u652f\u6301\uff0cSheetKit \u5c06\u652f\u6301 iOS 14\u3002<\/p><\/blockquote>\n\n\n\n<h5 class=\"wp-block-heading\">\u5b89\u88c5<\/h5>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>SheetKit \u652f\u6301 SPM \u5b89\u88c5\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/fatbobman\/SheetKit.git\" target=\"_blank\" rel=\"noreferrer noopener\">\u6e90\u5730\u5740<\/a><\/p>\n\n\n\n<p>SheetKit \u4e2d\u6bcf\u4e2a\u529f\u80fd\u7684\u4ee3\u7801\u90fd\u96c6\u4e2d\u5728\u4e00\u5230\u4e24\u4e2a\u6587\u4ef6\u4e2d\u3002\u5982\u679c\u53ea\u9700\u8981\u5176\u4e2d\u90e8\u5206\u7684\u529f\u80fd\uff0c\u76f4\u63a5\u5728\u9879\u76ee\u4e2d\u6dfb\u52a0\u5bf9\u5e94\u7684\u6587\u4ef6\u6216\u8bb8\u662f\u4e0d\u9519\u7684\u9009\u62e9\u3002<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">SheetKit \u529f\u80fd\u8be6\u89e3<\/h5>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p id=\"present\"><strong>present<\/strong><\/p>\n\n\n\n<p id=\"SheetKit_\u8c03\u7528\"><strong>SheetKit \u8c03\u7528<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-24-1024x371.png\" alt=\"\" class=\"wp-image-4907\" width=\"571\" height=\"207\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-24-1024x371.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-24-300x109.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-24-768x278.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-24-830x301.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-24-230x83.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-24-350x127.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-24-480x174.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-24.png 1160w\" sizes=\"(max-width: 571px) 100vw, 571px\" \/><\/figure><\/div>\n\n\n\n<p>\u5728\u4ee3\u7801\u4e2d\u4f7f\u7528 SheetKit \u5341\u5206\u5bb9\u6613\u3002\u652f\u6301\u4e24\u79cd\u65b9\u5f0f\uff1a\u76f4\u63a5\u4f7f\u7528 SheetKit \u7684\u5b9e\u4f8b\u3001\u5728\u89c6\u56fe\u4e2d\u4f7f\u7528\u73af\u5883\u503c\u3002\u6bd4\u5982\u4e0b\u9762\u7684\u4e24\u6bb5\u4ee3\u7801\u90fd\u5c06\u663e\u793a\u4e00\u4e2a\u6807\u51c6 Sheet\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Button(\"show sheet\"){\n   SheetKit().present{\n     Text(\"Hello world\")\n   }\n}\n<\/pre>\n\n\n\n<p>\u6216\u8005<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@Environment(\\.sheetKit) var sheetKit\n\nButton(\"show sheet\"){\n   sheetKit.present{\n     Text(\"Hello world\")\n   }\n}<\/pre>\n\n\n\n<p>SheetKit \u652f\u6301\u591a\u5c42\u6b21\u7684 Sheet \u5c55\u793a\uff0c\u4e0b\u9762\u4ee3\u7801\u5c06\u5c55\u793a\u4e24\u5c42 Sheet<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@Environment(\\.sheetKit) var sheetKit\n\nButton(\"show sheet\"){\n   sheetKit.present{\n     Button(\"show full sheet\"){\n       sheetKit.present(with:.fullScreenCover){\n         Text(\"Hello world\")\n       }\n     }\n   }\n}\n<\/pre>\n\n\n\n<p id=\"\u52a8\u753b\"><strong>\u52a8\u753b<\/strong><\/p>\n\n\n\n<p>SheetKit \u4e2d present \u548c dismiss \u7684\u52a8\u753b\u90fd\u662f\u53ef\u4ee5\u5173\u95ed\u7684\uff08\u5c24\u5176\u9002\u5408\u4e8e Deep link \u573a\u666f\uff09\u3002\u4f7f\u7528\u4e0b\u9762\u8bed\u53e5\u5c06\u5173\u95ed\u663e\u793a\u52a8\u753b<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SheetKit().present(animated: false)<\/pre>\n\n\n\n<p id=\"Sheet_\u7c7b\u578b\"><strong>Sheet \u7c7b\u578b<\/strong><\/p>\n\n\n\n<p>\u76ee\u524d SheetKit \u652f\u6301\u4e09\u79cd\u6a21\u6001\u89c6\u56fe\u7c7b\u578b\uff1asheet\u3001fullScreenCover\u3001bottomSheet\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-25-1024x428.png\" alt=\"\" class=\"wp-image-4909\" width=\"503\" height=\"210\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-25-1024x428.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-25-300x125.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-25-768x321.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-25-830x347.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-25-230x96.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-25-350x146.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-25-480x201.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-25.png 1028w\" sizes=\"(max-width: 503px) 100vw, 503px\" \/><\/figure><\/div>\n\n\n\n<p>\u4e0b\u9762\u7684\u4ee3\u7801\u5c06\u5c55\u793a\u4e00\u4e2a\u9884\u8bbe\u7684 bottomSheet \u89c6\u56fe\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sheetKit.present(with: .bottomSheet){\n  Text(\"Hello world\")\n}<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/01\/bottomSheet1-1778528.gif\" alt=\"\" class=\"wp-image-4910\" width=\"267\" height=\"577\"\/><\/figure><\/div>\n\n\n\n<p>bottomSheet \u53ef\u4ee5\u81ea\u5b9a\u4e49\u914d\u7f6e\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-26-1024x357.png\" alt=\"\" class=\"wp-image-4911\" width=\"624\" height=\"217\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-26-1024x357.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-26-300x104.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-26-768x267.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-26-830x289.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-26-230x80.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-26-350x122.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-26-480x167.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-26.png 1166w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/figure><\/div>\n\n\n\n<p>\u4e0b\u9762\u7684\u4ee3\u7801\u5c06\u521b\u5efa\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684 bottomSheet<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">let configuration = SheetKit.BottomSheetConfiguration(  detents: [.medium(),.large()],\n                                                        largestUndimmedDetentIdentifier: .medium,\n                                                        prefersGrabberVisible: true,\n                                                        prefersScrollingExpandsWhenScrolledToEdge: false,\n                                                        prefersEdgeAttachedInCompactHeight: false,\n                                                        widthFollowsPreferredContentSizeWhenEdgeAttached: true,\n                                                        preferredCornerRadius: 100)\n\nsheetKit.present(with: .customBottomSheet,configuration: configuration) {\n  Text(\"Hello world\")\n}<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/01\/Simulator-Screen-Shot-iPhone-13-Pro-Max-2021-09-16-at-16.15.08.png\" alt=\"\" class=\"wp-image-4912\" width=\"288\" height=\"623\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/Simulator-Screen-Shot-iPhone-13-Pro-Max-2021-09-16-at-16.15.08.png 400w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/Simulator-Screen-Shot-iPhone-13-Pro-Max-2021-09-16-at-16.15.08-139x300.png 139w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/Simulator-Screen-Shot-iPhone-13-Pro-Max-2021-09-16-at-16.15.08-230x497.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/Simulator-Screen-Shot-iPhone-13-Pro-Max-2021-09-16-at-16.15.08-350x757.png 350w\" sizes=\"(max-width: 288px) 100vw, 288px\" \/><\/figure><\/div>\n\n\n\n<p id=\"\u6a21\u6001\u89c6\u56fe\u9ad8\u5ea6\u53d8\u5316\u63d0\u9192\"><strong>\u6a21\u6001\u89c6\u56fe\u9ad8\u5ea6\u53d8\u5316\u63d0\u9192<\/strong><\/p>\n\n\n\n<p>\u5f53 bottomSheet \u5728\u4e0d\u540c\u9ad8\u5ea6\u53d8\u5316\u65f6\uff0c\u6709\u4e24\u79cd\u65b9\u5f0f\u53ef\u4ee5\u83b7\u5f97\u63d0\u9192\u3002<\/p>\n\n\n\n<p>\u65b9\u6cd5 1\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@State var detent:UISheetPresentationController.Detent.Identifier = .medium\n\nButton(\"Show\"){\n  sheetKit.present(with: .bottomSheet,detentIdentifier: $detent){\n    Text(\"Hello worl\")\n  }\n}\n.onChange(of: detent){ value in\n    print(value)\n}\n<\/pre>\n\n\n\n<p>\u65b9\u6cd5 2\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@State var publisher = NotificationCenter.default.publisher(for: .bottomSheetDetentIdentifierDidChanged, object: nil)\n\n.onReceive(publisher){ notification in\n       guard let obj = notification.object else {return}\n       print(obj)\n}\n<\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u5f53\u91c7\u7528\u65b9\u6cd5 2 \u65f6\uff0c\u5982\u679c\u9700\u8981\u5c55\u793a\u591a\u5c42 bottomSheet\uff0c\u8bf7\u4e3a\u4e0d\u540c\u5c42\u6b21\u7684\u89c6\u56fe\u5b9a\u4e49\u4e0d\u540c\u540d\u79f0\u7684 Notification.Name<\/p><\/blockquote>\n\n\n\n<p><strong>dismissAllSheets<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-27-1024x113.png\" alt=\"\" class=\"wp-image-4914\" width=\"657\" height=\"72\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-27-1024x113.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-27-300x33.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-27-768x85.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-27-830x91.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-27-230x25.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-27-350x39.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-27-480x53.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/\u56fe\u7247-27.png 1162w\" sizes=\"(max-width: 657px) 100vw, 657px\" \/><\/figure><\/div>\n\n\n\n<p>SheetKit \u652f\u6301\u5feb\u901f\u53d6\u6d88\u5168\u90e8\u6b63\u5728\u663e\u793a\u7684\u6a21\u6001\u89c6\u56fe\uff08\u65e0\u8bba\u8be5\u6a21\u6001\u89c6\u56fe\u662f\u5426\u7531 SheetKit \u5c55\u793a\uff09\u3002\u4f7f\u7528\u4e0b\u9762\u7684\u4ee3\u7801<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SheetKit().dismissAllSheets()<\/pre>\n\n\n\n<p>\u652f\u6301\u52a8\u753b\u63a7\u5236\u53ca onDisappear<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SheetKit().dismissAllSheets(animated: false, completion: {\n        print(\"sheet has dismiss\")\n    })<\/pre>\n\n\n\n<p><strong>dismiss<\/strong><\/p>\n\n\n\n<p>\u5982\u679c\u53ea\u60f3\u53d6\u6d88\u6700\u4e0a\u5c42\u7684\u6a21\u6001\u89c6\u56fe\uff0c\u53ef\u4ee5\u4f7f\u7528 dismiss<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    SheetKit().dismiss()<\/pre>\n\n\n\n<p>\u540c\u6837\u652f\u6301\u52a8\u753b\u63a7\u5236<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u5982\u679c\u5728\u89c6\u56fe\u5916\u6267\u884c SheetKit \u65b9\u6cd5\uff0c\u8bf7\u52a1\u5fc5\u4fdd\u8bc1\u4ee3\u7801\u8fd0\u884c\u5728\u4e3b\u7ebf\u7a0b\u4e0a\u3002\u53ef\u4ee5\u4f7f\u7528\u4f8b\u5982 DispatchQueue.main.async \u6216\u8005 MainActor.run \u7b49\u5f62\u5f0f\u3002<\/p><\/blockquote>\n\n\n\n<p><strong>interactiveDismissDisabled<\/strong><\/p>\n\n\n\n<p>SwiftUI 3.0 \u7684 interactiveDismissDisabled \u52a0\u5f3a\u7248\uff0c\u5728\u901a\u8fc7\u4ee3\u7801\u63a7\u5236\u662f\u5426\u5141\u8bb8\u624b\u52bf\u53d6\u6d88\u7684\u57fa\u7840\u4e0a\uff0c\u589e\u52a0\u4e86\u5f53\u7528\u6237\u4f7f\u7528\u624b\u52bf\u53d6\u6d88\u65f6\u53ef\u4ee5\u83b7\u5f97\u901a\u77e5\u7684\u80fd\u529b\u3002<\/p>\n\n\n\n<p>\u66f4\u591a\u4fe1\u606f\u8bf7\u53c2\u9605 <a href=\"https:\/\/www.fatbobman.com\/posts\/newInteractiveDismissDiabled\/\">\u5982\u4f55\u5728 SwiftUI \u4e2d\u5b9e\u73b0 interactiveDismissDisabled<\/a><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>SheetKit \u4e2d\u7684 interactiveDismissDisabled \u4e3a\u4e86\u517c\u5bb9 bottomSheet \u505a\u4e86\u4e00\u5b9a\u7684\u6539\u52a8\uff0c\u5177\u4f53\u6539\u52a8\u8bf7\u53c2\u89c1\u6e90\u4ee3\u7801\u3002<\/p><\/blockquote>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">struct ContentView: View {\n    @State var sheet = false\n    var body: some View {\n        VStack {\n            Button(\"show sheet\") {\n                sheet.toggle()\n            }\n        }\n        .sheet(isPresented: $sheet) {\n            SheetView()\n        }\n    }\n}\n\nstruct SheetView: View {\n    @State var disable = false\n    @State var attempToDismiss = UUID()\n    var body: some View {\n        VStack {\n            Button(\"disable: \\(disable ? \"true\" : \"false\")\") {\n                disable.toggle()\n            }\n            .interactiveDismissDisabled(disable, attempToDismiss: $attempToDismiss)\n        }\n        .onChange(of: attempToDismiss) { _ in\n            print(\"try to dismiss sheet\")\n        }\n    }\n}<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/01\/dismissSheet.gif\" alt=\"\" class=\"wp-image-4915\" width=\"292\" height=\"631\"\/><\/figure><\/div>\n\n\n\n<p id=\"clearBackground\"><strong>clearBackground<\/strong><\/p>\n\n\n\n<p>\u5c06\u6a21\u6001\u89c6\u56fe\u7684\u80cc\u666f\u8bbe\u7f6e\u4e3a\u900f\u660e\u3002\u5728 SwiftUI3.0 \u4e2d\uff0c\u5df2\u7ecf\u53ef\u4ee5\u4f7f\u7528\u539f\u751f API \u751f\u6210\u5404\u79cd\u6bdb\u73bb\u7483\u6548\u679c\u4e86\u3002\u4f46\u53ea\u6709\u5c06\u6a21\u6001\u89c6\u56fe\u7684\u80cc\u666f\u8bbe\u7f6e\u4e3a\u900f\u660e\uff0c\u6bdb\u73bb\u7483\u6548\u679c\u624d\u80fd\u663e\u73b0\u51fa\u6765\u3002<\/p>\n\n\n\n<p>\u5728\u6a21\u6001\u89c6\u56fe\u4e2d\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">.clearBackground()<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ZStack {\n            Rectangle().fill(LinearGradient(colors: [.red, .green, .pink, .blue, .yellow, .cyan, .gray], startPoint: .topLeading, endPoint: .bottomTrailing))\n            Button(\"Show bottomSheet\") {\n                sheetKit.present(with: .bottomSheet, afterPresent: { print(\"presented\") }, onDisappear: { print(\"disappear\") }, detentIdentifier: $detent) {\n                    ZStack {\n                        Rectangle()\n                            .fill(.ultraThinMaterial)\n                        VStack {\n                            Text(\"Hello world\")\n                            Button(\"dismiss all\") {\n                                SheetKit().dismissAllSheets(animated: true, completion: {\n                                    print(\"sheet has dismiss\")\n                                })\n                            }\n                        }\n                    }\n                    .clearBackground()\n                    .ignoresSafeArea()\n                }\n            }\n            .foregroundColor(.white)\n            .buttonStyle(.bordered)\n            .controlSize(.large)\n            .tint(.green)\n        }\n        .ignoresSafeArea()<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/01\/Simulator-Screen-Shot-iPhone-13-Pro-Max-2021-09-16-at-19.19.34-1791208.png\" alt=\"\" class=\"wp-image-4916\" width=\"277\" height=\"599\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/Simulator-Screen-Shot-iPhone-13-Pro-Max-2021-09-16-at-19.19.34-1791208.png 400w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/Simulator-Screen-Shot-iPhone-13-Pro-Max-2021-09-16-at-19.19.34-1791208-139x300.png 139w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/Simulator-Screen-Shot-iPhone-13-Pro-Max-2021-09-16-at-19.19.34-1791208-230x497.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/01\/Simulator-Screen-Shot-iPhone-13-Pro-Max-2021-09-16-at-19.19.34-1791208-350x757.png 350w\" sizes=\"(max-width: 277px) 100vw, 277px\" \/><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>SheetKit \u662f\u4ec0\u4e48 SheetKit \u662f\u4e00\u4e2a SwiftUI \u6a21\u6001\u89c6\u56fe\u7684\u6269\u5c55\u5e93\u3002\u63d0\u4f9b\u4e86\u6570\u4e2a\u7528\u4e8e\u6a21\u6001\u89c6\u56fe\u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,5],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/4905"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4905"}],"version-history":[{"count":4,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/4905\/revisions"}],"predecessor-version":[{"id":4917,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/4905\/revisions\/4917"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4905"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4905"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4905"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}