{"id":3961,"date":"2025-06-01T11:41:55","date_gmt":"2025-06-05T03:49:55","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=3961"},"modified":"2025-06-05T11:41:55","modified_gmt":"2025-06-05T03:49:55","slug":"%e5%ad%b8%e7%bf%92%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8swift%e4%b8%ad%e7%9a%84%e5%88%86%e9%a0%81%e6%8e%a7%e5%88%b6%e5%99%a8","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/%e5%ad%b8%e7%bf%92%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8swift%e4%b8%ad%e7%9a%84%e5%88%86%e9%a0%81%e6%8e%a7%e5%88%b6%e5%99%a8\/","title":{"rendered":"2025 \u6700\u65b0 Swift \u7a0b\u5f0f\u6559\u5b78\uff1a\u6df1\u5165\u4e86\u89e3\u5982\u4f55\u4f7f\u7528 UIPageViewController \u5be6\u73fe\u5206\u9801\u63a7\u5236\u5668"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"Swift, UIPageViewController, \u5206\u9875\u63a7\u5236\u5668, \u6570\u636e\u6e90, \u5206\u9875\u5207\u6362\u52a8\u753b\"><\/p>\n<h1>2025 \u6700\u65b0 Swift \u7a0b\u5f0f\u6559\u5b78\uff1a\u6df1\u5165\u4e86\u89e3\u5982\u4f55\u4f7f\u7528 UIPageViewController \u5be6\u73fe\u5206\u9801\u63a7\u5236\u5668<\/h1>\n<p>\u5728Swift\u4e2d\uff0c\u5206\u9801\u63a7\u5236\u5668\u662f\u5e38\u7528\u7684\u7528\u6236\u4ecb\u9762\u63a7\u4ef6\uff0c\u80fd\u5920\u5e6b\u52a9\u7528\u6236\u66f4\u8f15\u9b06\u5730\u700f\u89bd\u548c\u64cd\u4f5c\u591a\u500b\u9801\u9762\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528Swift\u4e2d\u7684UIPageViewController\u985e\u4f86\u5be6\u73fe\u5206\u9801\u63a7\u5236\u5668\uff0c\u6db5\u84cb\u8a2d\u5b9a\u6578\u64da\u6e90\u3001\u5be6\u73fe\u5206\u9801\u5207\u63db\u52d5\u756b\u4ee5\u53ca\u932f\u8aa4\u6392\u9664\u548c\u5ef6\u4f38\u61c9\u7528\u7b49\u8cc7\u8a0a\u3002<\/p>\n<h2>\u4f7f\u7528UIPageViewController\u985e\u5be6\u73fe\u5206\u9801\u63a7\u5236\u5668<\/h2>\n<p>UIPageViewController\u985e\u662fSwift\u4e2d\u7528\u65bc\u5be6\u73fe\u5206\u9801\u63a7\u5236\u5668\u7684\u4e3b\u8981\u985e\u3002\u8981\u4f7f\u7528UIPageViewController\uff0c\u9996\u5148\u9700\u5275\u5efa\u4e00\u500b\u5be6\u4f8b\uff0c\u4e26\u8a2d\u5b9a\u5176transitionStyle\u5c6c\u6027\uff0c\u4ee5\u6307\u5b9a\u5206\u9801\u5207\u63db\u7684\u52d5\u756b\u6548\u679c\uff0c\u4f8b\u5982pageCurl\u6216scroll\u3002<\/p>\n<pre class=\"brush: swift\">\nlet pageViewController = UIPageViewController(transitionStyle: .pageCurl, navigationOrientation: .horizontal, options: nil)\n<\/pre>\n<p>\u63a5\u8457\uff0c\u9700\u8981\u70ba\u5206\u9801\u63a7\u5236\u5668\u8a2d\u5b9a\u6578\u64da\u6e90\uff0c\u4ee5\u4fbf\u6b63\u78ba\u986f\u793a\u6bcf\u500b\u9801\u9762\u7684\u5167\u5bb9\u3002UIPageViewController\u63d0\u4f9b\u4e86dataSource\u5c6c\u6027\uff0c\u9019\u662f\u4e00\u500b\u9075\u5faaUIPageViewControllerDataSource\u5354\u8b70\u7684\u5be6\u73fe\uff0c\u5fc5\u9808\u5be6\u73fe\u4ee5\u4e0b\u5169\u500b\u65b9\u6cd5\uff1a<\/p>\n<pre class=\"brush: swift\">\nfunc pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController?\nfunc pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController?\n<\/pre>\n<p>\u9019\u5169\u500b\u65b9\u6cd5\u7528\u65bc\u8fd4\u56de\u7576\u524d\u9801\u9762\u7684\u524d\u4e00\u9801\u548c\u5f8c\u4e00\u9801\u7684\u8996\u5716\u63a7\u5236\u5668\uff0c\u5f9e\u800c\u5be6\u73fe\u5206\u9801\u5207\u63db\u529f\u80fd\u3002<\/p>\n<h2>\u5be6\u73fe\u5206\u9801\u5207\u63db\u52d5\u756b<\/h2>\n<p>\u5728Swift\u4e2d\uff0c\u5229\u7528UIPageViewController\u7684transitionStyle\u5c6c\u6027\u53ef\u4ee5\u5be6\u73fe\u591a\u7a2e\u5206\u9801\u5207\u63db\u52d5\u756b\u6548\u679c\u3002\u8981\u5be6\u73fe\u9019\u4e9b\u52d5\u756b\uff0c\u9700\u8abf\u7528setViewControllers(_:direction:animated:completion:)\u65b9\u6cd5\uff0c\u50b3\u5165\u8981\u5207\u63db\u7684\u8996\u5716\u63a7\u5236\u5668\u53ca\u5207\u63db\u65b9\u5411\uff0c\u5c31\u80fd\u9054\u5230\u5206\u9801\u5207\u63db\u7684\u6548\u679c\u3002<\/p>\n<pre class=\"brush: swift\">\nlet viewController = \/\/ \u8981\u5207\u63db\u5230\u7684\u8996\u5716\u63a7\u5236\u5668\nlet direction: UIPageViewController.NavigationDirection = .forward \/\/ \u5207\u63db\u7684\u65b9\u5411\nlet animated = true \/\/ \u662f\u5426\u4f7f\u7528\u52d5\u756b\nlet completion: ((Bool) -> Void)? = nil \/\/ \u5207\u63db\u5b8c\u6210\u540e\u7684\u56de\u8abf\n\npageViewController.setViewControllers([viewController], direction: direction, animated: animated, completion: completion)\n<\/pre>\n<h2>\u932f\u8aa4\u6392\u9664<\/h2>\n<p>\u5728\u5be6\u4f5c\u904e\u7a0b\u4e2d\uff0c\u82e5\u9047\u5230\u9801\u9762\u7121\u6cd5\u6b63\u5e38\u5207\u63db\u7684\u554f\u984c\uff0c\u8acb\u6aa2\u67e5\u4ee5\u4e0b\u5e7e\u9ede\uff1a<br \/>\n1. \u78ba\u4fdddataSource\u5df2\u6b63\u78ba\u8a2d\u7f6e\u3002<br \/>\n2. \u6aa2\u67e5\u8fd4\u56de\u7684\u8996\u5716\u63a7\u5236\u5668\u662f\u5426\u6709\u6548\uff0c\u907f\u514d\u8fd4\u56denil\u3002<br \/>\n3. \u78ba\u4fdd\u5728\u4e3b\u57f7\u884c\u7dd2\u4e2d\u9032\u884cUI\u66f4\u65b0\u3002<\/p>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>UIPageViewController\u4e0d\u50c5\u53ef\u4ee5\u7528\u65bc\u7c21\u55ae\u7684\u9801\u9762\u5207\u63db\uff0c\u9084\u53ef\u4ee5\u8207\u5176\u4ed6UI\u5143\u4ef6\u7d50\u5408\u4f7f\u7528\uff0c\u5982\u5c0e\u822a\u6b04\u3001\u6a19\u7c64\u6b04\u7b49\uff0c\u5275\u5efa\u66f4\u8c50\u5bcc\u7684\u7528\u6236\u9ad4\u9a57\u3002\u6b64\u5916\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u81ea\u5b9a\u7fa9\u52d5\u756b\u4f86\u589e\u5f37\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u672c\u6587\u4ecb\u7d39\u4e86\u5982\u4f55\u4f7f\u7528Swift\u4e2d\u7684UIPageViewController\u4f86\u5be6\u73fe\u5206\u9801\u63a7\u5236\u5668\uff0c\u5305\u62ec\u8a2d\u7f6e\u6578\u64da\u6e90\u548c\u5be6\u73fe\u5206\u9801\u5207\u63db\u52d5\u756b\u7684\u8a73\u7d30\u6b65\u9a5f\u3002\u900f\u904e\u9019\u4e9b\u6280\u5de7\uff0c\u60a8\u53ef\u4ee5\u5feb\u901f\u69cb\u5efa\u529f\u80fd\u5f37\u5927\u7684\u5206\u9801\u63a7\u5236\u5668\uff0c\u4e26\u63d0\u5347\u60a8\u7684iOS\u61c9\u7528\u7a0b\u5f0f\u7684\u7528\u6236\u4ecb\u9762\u3002<\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<h3>1. \u5982\u4f55\u5728\u5206\u9801\u63a7\u5236\u5668\u4e2d\u6dfb\u52a0\u624b\u52e2\u652f\u6301\uff1f<\/h3>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528UIPanGestureRecognizer\u4f86\u6aa2\u6e2c\u7528\u6236\u7684\u62d6\u52d5\u624b\u52e2\uff0c\u4e26\u6839\u64da\u624b\u52e2\u7684\u4f4d\u7f6e\u4f86\u66f4\u6539\u986f\u793a\u7684\u8996\u5716\u63a7\u5236\u5668\u3002<\/p>\n<h3>2. UIPageViewController\u6709\u4ec0\u9ebc\u9650\u5236\u55ce\uff1f<\/h3>\n<p>UIPageViewController\u5728\u8655\u7406\u5927\u91cf\u9801\u9762\u6642\u53ef\u80fd\u6703\u5c0e\u81f4\u6027\u80fd\u554f\u984c\uff0c\u56e0\u6b64\u5efa\u8b70\u5c0d\u9801\u9762\u6578\u91cf\u9032\u884c\u5408\u7406\u63a7\u5236\u3002<\/p>\n<h3>3. \u5982\u4f55\u81ea\u5b9a\u7fa9\u5206\u9801\u63a7\u5236\u5668\u7684\u904e\u6e21\u52d5\u756b\uff1f<\/h3>\n<p>\u60a8\u53ef\u4ee5\u5275\u5efa\u81ea\u5b9a\u7fa9\u7684UIViewControllerTransitioningDelegate\u4f86\u63a7\u5236\u904e\u6e21\u52d5\u756b\uff0c\u4e26\u5728\u8a2d\u7f6e\u8996\u5716\u63a7\u5236\u5668\u6642\u4f7f\u7528\u9019\u500b\u81ea\u5b9a\u7fa9\u904e\u6e21\u3002<\/p>\n<p>&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528Swift\u4e2d\u7684\u5206\u9801\u63a7\u5236\u5668\uff0c\u5305\u62ec\u5982\u4f55\u4f7f\u7528UIPageViewController\u985e\u4f86\u5be6\u73fe\u5206\u9801\u63a7\u5236\u5668\u3001\u5982\u4f55\u70ba\u5206\u9801\u63a7\u5236\u5668\u8a2d\u7f6e\u6578\u64da\u6e90\u3001\u5982\u4f55\u5be6\u73fe\u5206\u9801\u5207\u63db\u52d5\u756b\u7b49\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","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-3961","post","type-post","status-publish","format-standard","hentry","category-ios","category-swift","tag-ios","tag-swift"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-11T","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3961","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=3961"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3961\/revisions"}],"predecessor-version":[{"id":3962,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3961\/revisions\/3962"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=3961"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=3961"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=3961"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}