{"id":6728,"date":"2025-05-31T12:46:16","date_gmt":"2025-06-05T05:02:16","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=6728"},"modified":"2025-06-05T12:46:16","modified_gmt":"2025-06-05T05:02:16","slug":"https-badgameshow-com-steven-42","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-42\/","title":{"rendered":"Swift \u5206\u9801\u63a7\u5236\u5668\u5be6\u73fe\u5206\u9801\u64cd\u4f5c\uff1a2025 \u5b8c\u6574\u6559\u5b78\u8207\u6700\u4f73\u5be6\u8e10"},"content":{"rendered":"<p>&#8220;`html<br \/>\n<meta name=\"keywords\" content=\"swift, UIPageViewController, \u5206\u9801\u63a7\u5236\u5668, iOS\u958b\u767c, macOS\u958b\u767c\"><\/p>\n<h2>\u4ec0\u9ebc\u662f Swift \u5206\u9801\u63a7\u5236\u5668<\/h2>\n<p>\n    Swift \u5206\u9801\u63a7\u5236\u5668\u662f\u4e00\u500b\u5f37\u5927\u7684\u5de5\u5177\uff0c\u4f7f\u958b\u767c\u8005\u80fd\u5920\u5728 iOS \u548c macOS \u61c9\u7528\u4e2d\u5be6\u73fe\u5206\u9801\u64cd\u4f5c\u3002\u5b83\u80fd\u5920\u5728\u55ae\u4e00\u8996\u5716\u4e2d\u986f\u793a\u591a\u500b\u9801\u9762\uff0c\u4e26\u5141\u8a31\u7528\u6236\u8f15\u9b06\u5207\u63db\u4e0d\u540c\u7684\u9801\u9762\u3002\u7121\u8ad6\u662f\u986f\u793a\u5716\u7247\u3001\u6587\u7ae0\u6216\u5176\u4ed6\u5167\u5bb9\uff0c\u5206\u9801\u63a7\u5236\u5668\u90fd\u80fd\u63d0\u5347\u7528\u6236\u9ad4\u9a57\u3002\n<\/p>\n<h2>\u5982\u4f55\u5be6\u73fe Swift \u5206\u9801\u63a7\u5236\u5668<\/h2>\n<p>\n    \u8981\u4f7f\u7528 Swift \u5206\u9801\u63a7\u5236\u5668\uff0c\u4f60\u9700\u8981\u5275\u5efa\u4e00\u500b <code>UIPageViewController<\/code> \u5c0d\u8c61\uff0c\u7136\u5f8c\u5c07\u5176\u6dfb\u52a0\u5230\u4f60\u7684\u8996\u5716\u4e2d\u3002\u4ee5\u4e0b\u662f\u5be6\u73fe\u7684\u6b65\u9a5f\uff1a\n<\/p>\n<h3>1. \u5275\u5efa UIPageViewController<\/h3>\n<pre><code class=\"language-swift line-numbers\">let pageViewController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)<\/code><\/pre>\n<h3>2. \u6dfb\u52a0 UIPageViewController \u5230\u8996\u5716<\/h3>\n<pre><code class=\"language-swift line-numbers\">addChild(pageViewController)\nview.addSubview(pageViewController.view)\npageViewController.didMove(toParent: self)<\/code><\/pre>\n<h3>3. \u8a2d\u7f6e\u986f\u793a\u7684\u9801\u9762<\/h3>\n<p>\n    \u63a5\u4e0b\u4f86\uff0c\u4f60\u9700\u8981\u8a2d\u7f6e <code>UIPageViewController<\/code> \u4ee5\u986f\u793a\u4f60\u9078\u64c7\u7684\u9801\u9762\u3002\u4f7f\u7528\u4ee5\u4e0b\u7a0b\u5f0f\u78bc\u4f86\u8a2d\u7f6e\u986f\u793a\u7684\u9801\u9762\uff1a\n<\/p>\n<pre><code class=\"language-swift line-numbers\">pageViewController.setViewControllers([viewController], direction: .forward, animated: false, completion: nil)<\/code><\/pre>\n<p>\n    \u5728\u9019\u6bb5\u7a0b\u5f0f\u78bc\u4e2d\uff0c\u4f60\u53ef\u4ee5\u6307\u5b9a\u8981\u986f\u793a\u7684\u9801\u9762\uff0c\u4ee5\u53ca\u5f9e\u54ea\u500b\u65b9\u5411\u986f\u793a\u5b83\u5011\u3002\n<\/p>\n<h3>4. \u76e3\u807d\u9801\u9762\u5207\u63db\u4e8b\u4ef6<\/h3>\n<p>\n    \u4f7f\u7528 <code>UIPageViewControllerDelegate<\/code> \u5354\u8b70\u4f86\u76e3\u807d\u9801\u9762\u5207\u63db\u4e8b\u4ef6\u3002\u4ee5\u4e0b\u662f\u8a2d\u7f6e\u59d4\u6d3e\u7684\u7a0b\u5f0f\u78bc\uff1a\n<\/p>\n<pre><code class=\"language-swift line-numbers\">pageViewController.delegate = self<\/code><\/pre>\n<p>\n    \u5be6\u4f5c <code>UIPageViewControllerDelegate<\/code> \u5354\u8b70\u4ee5\u63a5\u6536\u7528\u6236\u5207\u63db\u9801\u9762\u7684\u901a\u77e5\uff1a\n<\/p>\n<pre><code class=\"language-swift line-numbers\">func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {\n    \/\/ \u7576\u7528\u6236\u5207\u63db\u9801\u9762\u6642\u57f7\u884c\u7684\u4ee3\u78bc\n}<\/code><\/pre>\n<h2>\u932f\u8aa4\u6392\u9664\u53ca\u6700\u4f73\u5be6\u8e10<\/h2>\n<p>\n    &#8211; \u78ba\u4fdd\u6240\u6709\u9801\u9762\u8996\u5716\u63a7\u5236\u5668\u90fd\u5df2\u6b63\u78ba\u521d\u59cb\u5316\u3002<br \/>\n    &#8211; \u6aa2\u67e5 <code>didMove(toParent:)<\/code> \u662f\u5426\u5728\u6dfb\u52a0\u5b50\u8996\u5716\u63a7\u5236\u5668\u5f8c\u6b63\u78ba\u8abf\u7528\u3002<br \/>\n    &#8211; \u4fdd\u6301 <code>UIPageViewController<\/code> \u7684\u65b9\u5411\u4e00\u81f4\uff0c\u907f\u514d\u7528\u6236\u6df7\u6dc6\u3002\n<\/p>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\n    Swift \u5206\u9801\u63a7\u5236\u5668\u4e0d\u50c5\u53ef\u4ee5\u7528\u65bc\u986f\u793a\u975c\u614b\u5167\u5bb9\uff0c\u9084\u53ef\u4ee5\u7528\u65bc\u986f\u793a\u52d5\u614b\u8cc7\u6599\u3002\u4f8b\u5982\uff0c\u7d50\u5408\u7db2\u8def\u8acb\u6c42\u4f86\u52d5\u614b\u8f09\u5165\u9801\u9762\u5167\u5bb9\uff0c\u63d0\u5347\u61c9\u7528\u7684\u4e92\u52d5\u6027\u8207\u4f7f\u7528\u8005\u9ad4\u9a57\u3002\n<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u5206\u9801\u63a7\u5236\u5668-\ud83d\udcbb-\u5be6\u73fe\u5206\u9801\u64cd\u4f5c_1675394643.998153.webp\" alt=\"Swift \u5206\u9801\u63a7\u5236\u5668 \ud83d\udcbb \u5be6\u73fe\u5206\u9801\u64cd\u4f5c\" title=\"Swift\u5206\u9801\u63a7\u5236\u5668\u3001\u5206\u9801\u64cd\u4f5c\u3001Swift\u958b\u767c\u3001\u8cc7\u6599\u5206\u9801\u3001\u958b\u767c\u6548\u7387\" width=\"1200\" height=\"628\"\/><\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<h3>Q1: \u5982\u4f55\u5728 UIPageViewController \u4e2d\u6dfb\u52a0\u591a\u500b\u9801\u9762?<\/h3>\n<p>A: \u4f60\u53ef\u4ee5\u5275\u5efa\u4e00\u500b\u5305\u542b\u591a\u500b\u8996\u5716\u63a7\u5236\u5668\u7684\u6578\u7d44\uff0c\u4e26\u901a\u904e <code>setViewControllers<\/code> \u65b9\u6cd5\u5c07\u5b83\u5011\u6dfb\u52a0\u5230\u5206\u9801\u63a7\u5236\u5668\u4e2d\u3002<\/p>\n<h3>Q2: \u5982\u4f55\u81ea\u8a02\u9801\u9762\u5207\u63db\u52d5\u756b?<\/h3>\n<p>A: \u4f60\u53ef\u4ee5\u4fee\u6539 <code>transitionStyle<\/code> \u53c3\u6578\uff0c\u9078\u64c7\u4e0d\u540c\u7684\u52d5\u756b\u6548\u679c\uff0c\u4f8b\u5982\u7ffb\u9801\u6216\u6efe\u52d5\u3002<\/p>\n<h3>Q3: \u5982\u679c\u6211\u60f3\u8981\u5728\u9801\u9762\u5207\u63db\u6642\u66f4\u65b0\u9801\u9762\u6a19\u984c\uff0c\u8a72\u600e\u9ebc\u505a?<\/h3>\n<p>A: \u5be6\u4f5c <code>UIPageViewControllerDelegate<\/code> \u7684 <code>pageViewController(_:didFinishAnimating:previousViewControllers:transitionCompleted:)<\/code> \u65b9\u6cd5\uff0c\u6839\u64da\u7576\u524d\u986f\u793a\u7684\u8996\u5716\u63a7\u5236\u5668\u66f4\u65b0\u6a19\u984c\u3002<\/p>\n<p>&#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\u5206\u9801\u63a7\u5236\u5668\u4f86\u5be6\u73fe\u5206\u9801\u64cd\u4f5c\uff0c\u8b93\u958b\u767c\u8005\u53ef\u4ee5\u5feb\u901f\u7684\u5c07\u8cc7\u6599\u5206\u9801\uff0c\u63d0\u9ad8\u958b\u767c\u6548\u7387\u3002<\/p>\n","protected":false},"author":1,"featured_media":6726,"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-6728","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-\u5206\u9801\u63a7\u5236\u5668-\ud83d\udcbb-\u5be6\u73fe\u5206\u9801\u64cd\u4f5c_1675394643.998153.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1Kw","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6728","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=6728"}],"version-history":[{"count":0,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6728\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/6726"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=6728"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=6728"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=6728"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}