{"id":7210,"date":"2025-06-04T15:01:20","date_gmt":"2025-06-05T07:31:20","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=7210"},"modified":"2025-06-05T15:01:20","modified_gmt":"2025-06-05T07:31:20","slug":"https-badgameshow-com-steven-278","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-278\/","title":{"rendered":"Swift \u5168\u5c4f\u756b\u9762 (UIPresentationController) &#8211; 2025 \u6700\u65b0\u5be6\u4f5c\u6559\u5b78"},"content":{"rendered":"<p>&#8220;`html<br \/>\n<meta name=\"keywords\" content=\"swift, UIPresentationController, iOS, \u5168\u5c4f\u756b\u9762, Swift \u7a0b\u5f0f\u6559\u5b78\"><\/p>\n<h1>Swift \u5168\u5c4f\u756b\u9762 (UIPresentationController) &#8211; 2025 \u6700\u65b0\u5be6\u4f5c\u6559\u5b78<\/h1>\n<p>\u5728 iOS \u958b\u767c\u4e2d\uff0c`UIPresentationController` \u662f\u4e00\u500b\u5f37\u5927\u7684\u5de5\u5177\uff0c\u7528\u65bc\u5be6\u73fe\u5168\u5c4f\u756b\u9762\uff0c\u8b93\u61c9\u7528\u7a0b\u5f0f\u7684\u754c\u9762\u66f4\u52a0\u7f8e\u89c0\u548c\u6613\u65bc\u4f7f\u7528\u3002\u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5011\u5c07\u6df1\u5165\u63a2\u8a0e\u5982\u4f55\u4f7f\u7528 Swift \u5be6\u73fe `UIPresentationController`\uff0c\u63d0\u4f9b\u5be6\u4f5c\u7bc4\u4f8b\u3001\u932f\u8aa4\u6392\u9664\u5efa\u8b70\u4ee5\u53ca\u5ef6\u4f38\u61c9\u7528\u7684\u4ecb\u7d39\u3002<\/p>\n<h2>\u4ec0\u9ebc\u662f UIPresentationController\uff1f<\/h2>\n<p>`UIPresentationController` \u662f iOS \u6846\u67b6\u7684\u4e00\u90e8\u5206\uff0c\u4e3b\u8981\u7528\u65bc\u63a7\u5236\u8996\u5716\u63a7\u5236\u5668\u7684\u5448\u73fe\u65b9\u5f0f\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u500b\u53ef\u81ea\u5b9a\u7fa9\u7684\u65b9\u5f0f\u4f86\u986f\u793a\u5168\u5c4f\u6216\u534a\u5c4f\u7684\u5167\u5bb9\uff0c\u4e26\u4e14\u80fd\u5920\u7ba1\u7406\u904e\u6e21\u52d5\u756b\uff0c\u5f9e\u800c\u63d0\u5347\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n<h2>\u5982\u4f55\u4f7f\u7528 Swift \u4f86\u5be6\u73fe UIPresentationController\uff1f<\/h2>\n<p>\u4f7f\u7528 Swift \u5be6\u73fe `UIPresentationController` \u7684\u904e\u7a0b\u76f8\u5c0d\u7c21\u55ae\uff0c\u4e3b\u8981\u5305\u62ec\u4ee5\u4e0b\u5e7e\u500b\u6b65\u9a5f\uff1a<\/p>\n<h3>\u6b65\u9a5f 1: \u5b9a\u7fa9 UIPresentationController \u7684\u5b50\u985e\u5225<\/h3>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u5275\u5efa\u4e00\u500b\u5b50\u985e\u5225\uff0c\u9019\u500b\u985e\u5225\u5fc5\u9808\u7e7c\u627f\u81ea `UIPresentationController`\u3002<\/p>\n<pre><code class=\"language-swift line-numbers\">class MyPresentationController: UIPresentationController {\n    \/\/ \u81ea\u5b9a\u7fa9\u5c6c\u6027\u548c\u65b9\u6cd5\n}\n<\/code><\/pre>\n<h3>\u6b65\u9a5f 2: \u5be6\u73fe UIPresentationController \u7684\u65b9\u6cd5<\/h3>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u5be6\u73fe\u4e00\u4e9b\u95dc\u9375\u7684\u65b9\u6cd5\uff0c\u4f8b\u5982 `presentationTransitionWillBegin` \u548c `dismissalTransitionWillBegin`\uff0c\u9019\u4e9b\u65b9\u6cd5\u7528\u4f86\u63a7\u5236\u904e\u6e21\u52d5\u756b\u3002<\/p>\n<pre><code class=\"language-swift line-numbers\">class MyPresentationController: UIPresentationController {\n    override func presentationTransitionWillBegin() {\n        \/\/ \u6dfb\u52a0\u904e\u6e21\u52d5\u756b\n        if let coordinator = presentingViewController.transitionCoordinator {\n            coordinator.animate(alongsideTransition: { context in\n                \/\/ \u81ea\u5b9a\u7fa9\u52d5\u756b\n            })\n        }\n    }\n\n    override func dismissalTransitionWillBegin() {\n        \/\/ \u6dfb\u52a0\u904e\u6e21\u52d5\u756b\n        if let coordinator = presentingViewController.transitionCoordinator {\n            coordinator.animate(alongsideTransition: { context in\n                \/\/ \u81ea\u5b9a\u7fa9\u52d5\u756b\n            })\n        }\n    }\n}\n<\/code><\/pre>\n<h3>\u6b65\u9a5f 3: \u5c07 UIPresentationController \u52a0\u5165\u5230\u4f60\u7684\u61c9\u7528\u7a0b\u5f0f<\/h3>\n<p>\u6700\u5f8c\uff0c\u60a8\u9700\u8981\u5728\u9700\u8981\u7684\u5730\u65b9\u5275\u5efa\u4e26\u5448\u73fe `MyPresentationController` \u7684\u5be6\u4f8b\u3002<\/p>\n<pre><code class=\"language-swift line-numbers\">let presentationController = MyPresentationController(presentedViewController: viewController, presenting: presentingViewController)\npresentingViewController.present(presentationController, animated: true, completion: nil)\n<\/code><\/pre>\n<h2>\u932f\u8aa4\u6392\u9664<\/h2>\n<p>\u5728\u5be6\u4f5c `UIPresentationController` \u6642\uff0c\u60a8\u53ef\u80fd\u6703\u9047\u5230\u4ee5\u4e0b\u554f\u984c\uff1a<br \/>\n&#8211; **\u52d5\u756b\u4e0d\u555f\u52d5**\uff1a\u8acb\u6aa2\u67e5\u662f\u5426\u6b63\u78ba\u5be6\u73fe\u4e86\u904e\u6e21\u52d5\u756b\u7684\u59d4\u8a17\u65b9\u6cd5\u3002<br \/>\n&#8211; **\u8996\u5716\u672a\u6b63\u78ba\u986f\u793a**\uff1a\u78ba\u4fdd\u60a8\u5df2\u7d93\u6b63\u78ba\u8a2d\u7f6e\u4e86\u5448\u73fe\u7684\u8996\u5716\u63a7\u5236\u5668\u3002<\/p>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>`UIPresentationController` \u4e0d\u50c5\u53ef\u4ee5\u7528\u65bc\u5168\u5c4f\u756b\u9762\uff0c\u9084\u53ef\u4ee5\u7528\u4f86\u5be6\u73fe\u6a21\u614b\u8996\u5716\u3001\u5e95\u90e8\u5f48\u51fa\u8996\u5716\u7b49\u3002\u5982\u679c\u60a8\u60f3\u8981\u9032\u4e00\u6b65\u81ea\u5b9a\u7fa9\u8996\u5716\uff0c\u8003\u616e\u7d50\u5408 `UIViewControllerTransitioningDelegate` \u4f86\u5be6\u73fe\u8907\u96dc\u7684\u904e\u6e21\u6548\u679c\u3002<\/p>\n<h2>\u7d50\u8ad6<\/h2>\n<p>\u672c\u6587\u4ecb\u7d39\u4e86\u5982\u4f55\u4f7f\u7528 Swift \u5be6\u73fe `UIPresentationController`\uff0c\u4e26\u4e14\u63d0\u4f9b\u4e86\u8a73\u7d30\u7684\u7a0b\u5f0f\u78bc\u7bc4\u4f8b\u53ca\u932f\u8aa4\u6392\u9664\u5efa\u8b70\u3002\u5efa\u8b70\u958b\u767c\u8005\u5728 iOS \u61c9\u7528\u4e2d\u8003\u616e\u4f7f\u7528 `UIPresentationController` \u4f86\u63d0\u5347\u4f7f\u7528\u8005\u9ad4\u9a57\u3002<\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<h3>Q1: UIPresentationController \u8207\u5176\u4ed6\u5448\u73fe\u65b9\u5f0f\u6709\u4f55\u4e0d\u540c\uff1f<\/h3>\n<p>A1: `UIPresentationController` \u63d0\u4f9b\u66f4\u9ad8\u7684\u81ea\u5b9a\u7fa9\u6027\uff0c\u5141\u8a31\u958b\u767c\u8005\u63a7\u5236\u5448\u73fe\u904e\u7a0b\u4e2d\u7684\u52d5\u756b\u548c\u8996\u5716\u5c64\u7d1a\uff0c\u9019\u5728\u50b3\u7d71\u6a21\u614b\u5448\u73fe\u4e2d\u7121\u6cd5\u5be6\u73fe\u3002<\/p>\n<h3>Q2: \u5982\u4f55\u8655\u7406 UIPresentationController \u4e2d\u7684\u89f8\u63a7\u4e8b\u4ef6\uff1f<\/h3>\n<p>A2: \u60a8\u53ef\u4ee5\u5728 `MyPresentationController` \u4e2d\u91cd\u5beb `presentationTransitionWillBegin` \u65b9\u6cd5\uff0c\u6dfb\u52a0\u624b\u52e2\u8b58\u5225\u5668\u4f86\u8655\u7406\u89f8\u63a7\u4e8b\u4ef6\u3002<\/p>\n<h3>Q3: UIPresentationController \u662f\u5426\u652f\u6301 iPad\uff1f<\/h3>\n<p>A3: \u662f\u7684\uff0c`UIPresentationController` \u5728 iPad \u4e0a\u540c\u6a23\u9069\u7528\uff0c\u4e26\u4e14\u53ef\u4ee5\u6839\u64da\u8a2d\u5099\u7684\u5927\u5c0f\u81ea\u52d5\u8abf\u6574\u986f\u793a\u65b9\u5f0f\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u5168\u5c4f\u756b\u9762-UIPresentationController-\ud83d\udcaf_1675405038.5372741.webp\" alt=\"Swift \u5168\u5c4f\u756b\u9762 (UIPresentationController) \ud83d\udcaf\" title=\"Swift \u5168\u5c4f\u756b\u9762\u3001UIPresentationController\u3001Swift \u7a0b\u5f0f\u78bc\u3001Swift \u529f\u80fd\u3001Swift \u5be6\u73fe\" width=\"1200\" height=\"628\"\/><br \/>\n&#8220;`<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528Swift\u8a9e\u8a00\u4f86\u5be6\u73fe\u5168\u5c4f\u756b\u9762(UIPresentationController)\u7684\u529f\u80fd\uff0c\u4e26\u63d0\u4f9b\u7a0b\u5f0f\u78bc\u7bc4\u4f8b\uff0c\u8b93\u958b\u767c\u8005\u53ef\u4ee5\u5feb\u901f\u4e0a\u624b\uff0c\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528Swift\u4f86\u5be6\u73fe\u5168\u5c4f\u756b\u9762(UIPresentationController)\u7684\u529f\u80fd\u3002<\/p>\n","protected":false},"author":1,"featured_media":7209,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[174,5],"tags":[173,9],"class_list":["post-7210","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ios","category-swift","tag-ios","tag-swift"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u5168\u5c4f\u756b\u9762-UIPresentationController-\ud83d\udcaf_1675405038.5372741.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1Si","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=7210"}],"version-history":[{"count":2,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7210\/revisions"}],"predecessor-version":[{"id":13105,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7210\/revisions\/13105"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/7209"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=7210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=7210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=7210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}