{"id":6654,"date":"2025-06-03T12:26:20","date_gmt":"2025-06-05T04:34:20","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/uncategorized\/https-badgameshow-com-steven-5\/"},"modified":"2025-06-05T12:26:20","modified_gmt":"2025-06-05T04:34:20","slug":"https-badgameshow-com-steven-5","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-5\/","title":{"rendered":"Swift 2025 \u6700\u65b0\u7248\uff1a\u5be6\u73fe\u62bd\u5c5c\u6548\u679c\u7684\u5b8c\u6574\u6559\u5b78 \ud83e\uddf9"},"content":{"rendered":"<p>&#8220;`html<br \/>\n<meta name=\"keywords\" content=\"swift, \u62bd\u5c5c\u6548\u679c, Swift \u7a0b\u5f0f\u6559\u5b78, iOS \u958b\u767c\"><\/p>\n<h2>\u4ec0\u9ebc\u662f\u62bd\u5c5c\u6548\u679c\uff1f<\/h2>\n<p>\u62bd\u5c5c\u6548\u679c\u662f\u4e00\u7a2e\u5e38\u898b\u7684 UI \u6548\u679c\uff0c\u80fd\u8b93\u4f60\u7684\u61c9\u7528\u7a0b\u5f0f\u64c1\u6709\u66f4\u597d\u7684\u5c64\u6b21\u611f\u548c\u4f7f\u7528\u9ad4\u9a57\u3002\u5728 iOS \u958b\u767c\u4e2d\uff0c\u62bd\u5c5c\u6548\u679c\u901a\u5e38\u7528\u65bc\u5074\u908a\u83dc\u55ae\u6216\u984d\u5916\u7684\u9078\u9805\uff0c\u8b93\u4f7f\u7528\u8005\u53ef\u4ee5\u65b9\u4fbf\u5730\u5c0e\u822a\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528 Swift 2025 \u6700\u65b0\u8a9e\u6cd5\u4f86\u5be6\u73fe\u9019\u4e00\u6548\u679c\u3002<\/p>\n<h2>\u5982\u4f55\u4f7f\u7528 Swift \u5be6\u73fe\u62bd\u5c5c\u6548\u679c\uff1f<\/h2>\n<p>\u4f7f\u7528 Swift \u5be6\u73fe\u62bd\u5c5c\u6548\u679c\u76f8\u5c0d\u7c21\u55ae\u3002\u4ee5\u4e0b\u662f\u8a73\u7d30\u6b65\u9a5f\u548c\u5b8c\u6574\u7bc4\u4f8b\uff1a<\/p>\n<h3>1. \u5275\u5efa DrawerViewController \u985e<\/h3>\n<p>\u9996\u5148\uff0c\u4f60\u9700\u8981\u5275\u5efa\u4e00\u500b <code>DrawerViewController<\/code> \u7684\u5b50\u985e\uff0c\u4e26\u8a2d\u7f6e\u70ba\u4f60\u7684\u61c9\u7528\u7a0b\u5f0f\u7684\u6839\u8996\u5716\u63a7\u5236\u5668\u3002<\/p>\n<pre><code class=\"language-swift line-numbers\">class DrawerViewController: UIViewController {\n    var drawerView: UIView!\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        setupDrawerView() \/\/ \u547c\u53eb\u8a2d\u5b9a\u62bd\u5c5c\u8996\u5716\u7684\u65b9\u6cd5\n    }\n\n    override func viewDidAppear(_ animated: Bool) {\n        super.viewDidAppear(animated)\n        showDrawer() \/\/ \u547c\u53eb\u986f\u793a\u62bd\u5c5c\u7684\u65b9\u6cd5\n    }\n\n    private func setupDrawerView() {\n        drawerView = UIView()\n        drawerView.frame = CGRect(x: -self.view.frame.width, y: 0, width: self.view.frame.width * 0.8, height: self.view.frame.height)\n        drawerView.backgroundColor = .gray \/\/ \u8a2d\u5b9a\u62bd\u5c5c\u984f\u8272\n        self.view.addSubview(drawerView)\n    }\n\n    private func showDrawer() {\n        UIView.animate(withDuration: 0.3) {\n            self.drawerView.frame.origin.x = 0\n        }\n    }\n}\n<\/code><\/pre>\n<h3>2. \u6dfb\u52a0\u624b\u52e2\u8b58\u5225\u5668<\/h3>\n<p>\u70ba\u4e86\u8b93\u4f7f\u7528\u8005\u53ef\u4ee5\u8f15\u9b06\u5730\u958b\u555f\u548c\u95dc\u9589\u62bd\u5c5c\uff0c\u6211\u5011\u9700\u8981\u6dfb\u52a0\u624b\u52e2\u8b58\u5225\u5668\u3002<\/p>\n<pre><code class=\"language-swift line-numbers\">private func setupGestureRecognizers() {\n    let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(showDrawer))\n    swipeRight.direction = .right\n    self.view.addGestureRecognizer(swipeRight)\n\n    let swipeLeft = UISwipeGestureRecognizer(target: self, action: #selector(hideDrawer))\n    swipeLeft.direction = .left\n    self.view.addGestureRecognizer(swipeLeft)\n}\n\n@objc private func hideDrawer() {\n    UIView.animate(withDuration: 0.3) {\n        self.drawerView.frame.origin.x = -self.drawerView.frame.width\n    }\n}\n<\/code><\/pre>\n<h2>\u932f\u8aa4\u6392\u9664<\/h2>\n<p>\u5982\u679c\u62bd\u5c5c\u6548\u679c\u672a\u6b63\u5e38\u986f\u793a\uff0c\u8acb\u6aa2\u67e5\u4ee5\u4e0b\u5e7e\u9ede\uff1a<\/p>\n<ul>\n<li>\u78ba\u4fdd <code>drawerView<\/code> \u7684\u521d\u59cb\u4f4d\u7f6e\u8a2d\u7f6e\u70ba\u87a2\u5e55\u5916\uff08\u4f8b\u5982\uff0c<code>x: -self.view.frame.width<\/code>\uff09\u3002<\/li>\n<li>\u6aa2\u67e5\u52d5\u756b\u7684\u6301\u7e8c\u6642\u9593\uff0c\u78ba\u4fdd\u4e0d\u6703\u8a2d\u7f6e\u5f97\u904e\u77ed\u3002<\/li>\n<li>\u78ba\u8a8d\u624b\u52e2\u8b58\u5225\u5668\u5df2\u6b63\u78ba\u8a2d\u7f6e\uff0c\u4e26\u4e14\u65b9\u6cd5\u540d\u7121\u8aa4\u3002<\/li>\n<\/ul>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u9664\u4e86\u57fa\u672c\u7684\u62bd\u5c5c\u6548\u679c\uff0c\u4f60\u53ef\u4ee5\u9032\u4e00\u6b65\u81ea\u8a02\u62bd\u5c5c\u7684\u5167\u5bb9\uff0c\u4f8b\u5982\u6dfb\u52a0\u6309\u9215\u4f86\u57f7\u884c\u7279\u5b9a\u64cd\u4f5c\uff0c\u6216\u4f7f\u7528\u4e0d\u540c\u7684\u984f\u8272\u548c\u6a23\u5f0f\u4f86\u63d0\u5347\u7f8e\u89c0\u5ea6\u3002\u63a2\u7d22\u66f4\u591a\u7684 UI \u8a2d\u8a08\uff0c\u8b93\u4f60\u7684\u61c9\u7528\u7a0b\u5f0f\u66f4\u52a0\u5438\u5f15\u4eba\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u5be6\u73fe\u62bd\u5c5c\u6548\u679c-\ud83e\uddf9_1675393169.2609248.webp\" alt=\"Swift \u5be6\u73fe\u62bd\u5c5c\u6548\u679c \ud83e\uddf9\" title=\"Swift \u62bd\u5c5c\u6548\u679c\u5be6\u73fe\u793a\u4f8b\" width=\"1200\" height=\"628\"\/><\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<h3>Q1: \u5982\u4f55\u8abf\u6574\u62bd\u5c5c\u7684\u5bec\u5ea6\uff1f<\/h3>\n<p>A1: \u4f60\u53ef\u4ee5\u5728 <code>setupDrawerView()<\/code> \u65b9\u6cd5\u4e2d\u8abf\u6574 <code>drawerView<\/code> \u7684\u5bec\u5ea6\uff0c\u4f8b\u5982\u4f7f\u7528 <code>self.view.frame.width * 0.8<\/code> \u4f86\u8a2d\u7f6e\u70ba 80% \u7684\u87a2\u5e55\u5bec\u5ea6\u3002<\/p>\n<h3>Q2: \u62bd\u5c5c\u6548\u679c\u6709\u6c92\u6709\u66f4\u8907\u96dc\u7684\u5be6\u4f5c\u65b9\u5f0f\uff1f<\/h3>\n<p>A2: \u53ef\u4ee5\u4f7f\u7528 <code>UIViewControllerTransitioningDelegate<\/code> \u4f86\u5be6\u73fe\u66f4\u8907\u96dc\u7684\u8f49\u5834\u6548\u679c\uff0c\u4e26\u7d50\u5408 <code>UIViewController<\/code> \u7684\u5448\u73fe\u65b9\u5f0f\u9032\u884c\u81ea\u8a02\u3002<\/p>\n<p>&#8220;`<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528Swift\u8a9e\u8a00\u4f86\u5be6\u73fe\u62bd\u5c5c\u6548\u679c\uff0c\u4e26\u8a73\u7d30\u4ecb\u7d39Swift\u4e2d\u7684methods()\u51fd\u6578\u529f\u80fd\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u5b83\u5011\u4f86\u5be6\u73fe\u62bd\u5c5c\u6548\u679c\u3002<\/p>\n","protected":false},"author":1,"featured_media":6653,"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-6654","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-\u5be6\u73fe\u62bd\u5c5c\u6548\u679c-\ud83e\uddf9_1675393169.2609248.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1Jk","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6654","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=6654"}],"version-history":[{"count":0,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6654\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/6653"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=6654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=6654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=6654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}