{"id":7264,"date":"2025-05-30T12:37:21","date_gmt":"2025-06-05T04:58:21","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=7264"},"modified":"2025-06-05T12:37:21","modified_gmt":"2025-06-05T04:58:21","slug":"https-badgameshow-com-steven-304","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-304\/","title":{"rendered":"2025 \u6700\u65b0 Swift \u5716\u7247\u8f2a\u64ad\u5668\u6559\u5b78\uff1a\u6253\u9020\u5f15\u4eba\u6ce8\u76ee\u7684 App \u529f\u80fd \ud83d\udcf7\ud83d\udd04"},"content":{"rendered":"<p>&#8220;`html<br \/>\n<meta name=\"keywords\" content=\"swift, \u5716\u7247\u8f2a\u64ad\u5668, UIPageViewController, iOS \u958b\u767c, Swift \u6559\u5b78\"><\/p>\n<h2>Swift \u5716\u7247\u8f2a\u64ad\u5668 \ud83d\udcf7\ud83d\udd04<\/h2>\n<p>Swift \u662f\u4e00\u7a2e\u5feb\u901f\u3001\u5b89\u5168\u7684\u7a0b\u5f0f\u8a9e\u8a00\uff0c\u8b93\u958b\u767c\u8005\u80fd\u5920\u8fc5\u901f\u958b\u767c\u51fa\u529f\u80fd\u5f37\u5927\u7684 App\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528 Swift \u4f86\u958b\u767c\u4e00\u500b\u5716\u7247\u8f2a\u64ad\u5668\uff0c\u9019\u4e0d\u50c5\u80fd\u63d0\u5347\u4f60\u7684 App \u8996\u89ba\u5438\u5f15\u529b\uff0c\u4e5f\u80fd\u589e\u5f37\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n<h3>\u70ba\u4f55\u4f7f\u7528\u5716\u7247\u8f2a\u64ad\u5668\uff1f<\/h3>\n<p>\u5716\u7247\u8f2a\u64ad\u5668\u662f\u4e00\u7a2e\u5e38\u898b\u7684 App \u529f\u80fd\uff0c\u80fd\u5920\u6709\u6548\u5c55\u793a\u591a\u5f35\u5716\u7247\uff0c\u5438\u5f15\u7528\u6236\u7684\u6ce8\u610f\u529b\u3002\u5b83\u9069\u7528\u65bc\u8a31\u591a\u5834\u666f\uff0c\u5982\u7522\u54c1\u5c55\u793a\u3001\u76f8\u518a\u700f\u89bd\u7b49\u3002<\/p>\n<h3>\u4f7f\u7528 UIPageViewController \u958b\u767c\u5716\u7247\u8f2a\u64ad\u5668<\/h3>\n<p>\u5728 Swift \u4e2d\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 <strong>UIPageViewController<\/strong> \u4f86\u8f15\u9b06\u958b\u767c\u5716\u7247\u8f2a\u64ad\u5668\u3002\u9019\u500b\u6846\u67b6\u63d0\u4f9b\u4e86\u4e00\u500b\u7c21\u55ae\u7684 API \u4f86\u63a7\u5236\u8f2a\u64ad\u5668\u7684\u884c\u70ba\u3002<\/p>\n<h3>\u6b65\u9a5f 1\uff1a\u5275\u5efa UIPageViewController \u5be6\u4f8b<\/h3>\n<p>\u9996\u5148\uff0c\u5275\u5efa\u4e00\u500b <code>UIPageViewController<\/code> \u7684\u5be6\u4f8b\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">let pageViewController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)<\/code><\/pre>\n<h3>\u6b65\u9a5f 2\uff1a\u5275\u5efa\u6578\u64da\u6e90<\/h3>\n<p>\u63a5\u4e0b\u4f86\uff0c\u9700\u8981\u5275\u5efa\u4e00\u500b UIViewController \u7684\u5b50\u985e\uff0c\u4e26\u5c07\u5b83\u8a2d\u7f6e\u70ba <code>pageViewController<\/code> \u7684 dataSource\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">class PageViewControllerDataSource: NSObject, UIPageViewControllerDataSource {\n    var images: [String] = [] \/\/ \u5132\u5b58\u5716\u7247\u7684 URL\n    \n    func setImages(_ imageArray: [String]) {\n        images = imageArray\n    }\n\n    func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {\n        \/\/ \u5be6\u73fe\u524d\u4e00\u500b\u9801\u9762\u7684\u908f\u8f2f\n    }\n\n    func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {\n        \/\/ \u5be6\u73fe\u4e0b\u4e00\u500b\u9801\u9762\u7684\u908f\u8f2f\n    }\n}\n\nlet dataSource = PageViewControllerDataSource()\npageViewController.dataSource = dataSource<\/code><\/pre>\n<h3>\u6b65\u9a5f 3\uff1a\u5be6\u73fe UIPageViewControllerDataSource \u5354\u8b70\u65b9\u6cd5<\/h3>\n<p>\u9700\u8981\u5be6\u73fe <code>UIPageViewControllerDataSource<\/code> \u5354\u8b70\u4e2d\u7684\u5169\u500b\u65b9\u6cd5\uff0c\u9019\u5169\u500b\u65b9\u6cd5\u6703\u5728\u7528\u6236\u9ede\u64ca\u8f2a\u64ad\u5668\u6642\u88ab\u8abf\u7528\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {\n    \/\/ \u8fd4\u56de\u524d\u4e00\u500b\u5716\u7247\u7684 UIViewController\n}\n\nfunc pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {\n    \/\/ \u8fd4\u56de\u4e0b\u4e00\u500b\u5716\u7247\u7684 UIViewController\n}<\/code><\/pre>\n<h3>\u6b65\u9a5f 4\uff1a\u5c07 UIPageViewController \u6dfb\u52a0\u5230\u4f60\u7684 App \u4e2d<\/h3>\n<p>\u6700\u5f8c\uff0c\u5c07 <code>pageViewController<\/code> \u6dfb\u52a0\u5230\u4f60\u7684 App \u7684\u8996\u5716\u5c64\u7d1a\u4e2d\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">addChild(pageViewController)\nview.addSubview(pageViewController.view)\npageViewController.didMove(toParent: self)<\/code><\/pre>\n<h3>\u932f\u8aa4\u6392\u9664<\/h3>\n<p>\u5982\u679c\u8f2a\u64ad\u5668\u7121\u6cd5\u986f\u793a\u5716\u7247\uff0c\u8acb\u78ba\u4fdd\uff1a<\/p>\n<ul>\n<li>\u6578\u64da\u6e90\u6b63\u78ba\u8a2d\u7f6e\u3002<\/li>\n<li>\u5716\u7247 URL \u6b63\u78ba\u4e14\u53ef\u8a2a\u554f\u3002<\/li>\n<li>UIPageViewController \u7684\u8996\u5716\u5df2\u6b63\u78ba\u6dfb\u52a0\u5230\u7236\u8996\u5716\u4e2d\u3002<\/li>\n<\/ul>\n<h3>\u5ef6\u4f38\u61c9\u7528<\/h3>\n<p>\u4f60\u53ef\u4ee5\u6839\u64da\u9700\u8981\u81ea\u5b9a\u7fa9\u5716\u7247\u8f2a\u64ad\u5668\u7684\u6a23\u5f0f\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li>\u6dfb\u52a0\u904e\u6e21\u52d5\u756b\u6548\u679c\u3002<\/li>\n<li>\u8a2d\u7f6e\u81ea\u52d5\u64ad\u653e\u529f\u80fd\u3002<\/li>\n<li>\u589e\u52a0\u5716\u7247\u7684\u7e2e\u653e\u529f\u80fd\u3002<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u5716\u7247\u8f2a\u64ad\u5668-\ud83d\udcf7\ud83d\udd04_1675409798.4268649.webp\" alt=\"Swift \u5716\u7247\u8f2a\u64ad\u5668 \ud83d\udcf7\ud83d\udd04\" title=\"Swift \u5716\u7247\u8f2a\u64ad\u5668, Swift \u8a9e\u8a00, \u5716\u7247\u8f2a\u64ad\u5668, \u529f\u80fd\u8c50\u5bcc, \u51fd\u6578\u65b9\u6cd5\" 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\u8f2a\u64ad\u5668\u4e2d\u6dfb\u52a0\u81ea\u52d5\u64ad\u653e\u529f\u80fd\uff1f<\/h3>\n<p>A1: \u4f60\u53ef\u4ee5\u5229\u7528 <code>Timer<\/code> \u4f86\u5b9a\u671f\u5207\u63db\u9801\u9762\uff0c\u5be6\u73fe\u81ea\u52d5\u64ad\u653e\u7684\u6548\u679c\u3002<\/p>\n<h3>Q2: \u5982\u4f55\u81ea\u5b9a\u7fa9\u9801\u9762\u7684\u986f\u793a\u6a23\u5f0f\uff1f<\/h3>\n<p>A2: \u4f60\u53ef\u4ee5\u5728 <code>UIViewController<\/code> \u7684\u5b50\u985e\u4e2d\u81ea\u5b9a\u7fa9\u5716\u7247\u7684\u986f\u793a\u6a23\u5f0f\uff0c\u5982\u6dfb\u52a0\u6a19\u984c\u6216\u63cf\u8ff0\u3002<\/p>\n<h3>Q3: \u7576\u7528\u6236\u6ed1\u52d5\u6642\u5982\u4f55\u66f4\u65b0\u9801\u9762\u6307\u793a\u5668\uff1f<\/h3>\n<p>A3: \u4f60\u53ef\u4ee5\u5728 <code>UIPageViewControllerDelegate<\/code> \u4e2d\u5be6\u73fe <code>pageViewController(_:didFinishAnimating:previousViewControllers:transitionCompleted:)<\/code> \u65b9\u6cd5\u4f86\u66f4\u65b0\u6307\u793a\u5668\u7684\u72c0\u614b\u3002<\/p>\n<p>&#8220;`<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981:\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528Swift\u8a9e\u8a00\u5efa\u7acb\u4e00\u500b\u5716\u7247\u8f2a\u64ad\u5668\uff0c\u4e26\u5229\u7528\u5176\u4e2d\u7684\u51fd\u6578\u548c\u65b9\u6cd5\u4f86\u5efa\u7acb\u4e00\u500b\u5177\u6709\u8c50\u5bcc\u529f\u80fd\u7684\u5716\u7247\u8f2a\u64ad\u5668\u3002<\/p>\n","protected":false},"author":1,"featured_media":7263,"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-7264","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-\u5716\u7247\u8f2a\u64ad\u5668-\ud83d\udcf7\ud83d\udd04_1675409798.4268649.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1Ta","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7264","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=7264"}],"version-history":[{"count":0,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7264\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/7263"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=7264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=7264"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=7264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}