{"id":7720,"date":"2025-05-29T13:46:52","date_gmt":"2025-06-05T06:42:51","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=7720"},"modified":"2025-06-05T13:46:52","modified_gmt":"2025-06-05T06:42:51","slug":"https-badgameshow-com-steven-503","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-503\/","title":{"rendered":"SwiftUI \u624b\u52e2\u6aa2\u6e2c\uff1a2025 \u6700\u65b0\u7a0b\u5f0f\u6559\u5b78\u8207\u5be6\u4f5c\u7bc4\u4f8b"},"content":{"rendered":"<p>&#8220;`html<br \/>\n<meta name=\"keywords\" content=\"swift, SwiftUI, \u624b\u52e2\u6aa2\u6e2c\" \/><\/p>\n<h2>\u4ecb\u7d39 SwiftUI \u8207\u624b\u52e2\u6aa2\u6e2c<\/h2>\n<p>SwiftUI \u662f Apple \u5728 WWDC 2019 \u63a8\u51fa\u7684\u5168\u65b0\u6846\u67b6\uff0c\u65e8\u5728\u8b93\u958b\u767c\u8005\u8f15\u9b06\u5275\u5efa\u7f8e\u89c0\u7684\u61c9\u7528\u7a0b\u5f0f\u3002\u5176\u4e2d\uff0c\u624b\u52e2\u6aa2\u6e2c\u529f\u80fd\u4f7f\u5f97\u958b\u767c\u8005\u80fd\u5920\u8f15\u9b06\u5be6\u73fe\u6709\u8da3\u4e14\u4e92\u52d5\u6027\u5f37\u7684\u7528\u6236\u754c\u9762\u3002\u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5011\u5c07\u6df1\u5165\u63a2\u8a0e\u5982\u4f55\u5728 SwiftUI \u4e2d\u4f7f\u7528\u624b\u52e2\u6aa2\u6e2c\uff0c\u4e26\u63d0\u4f9b\u6700\u65b0\u7684\u8a9e\u6cd5\u8207\u6700\u4f73\u5be6\u8e10\u3002<\/p>\n<h2>\u624b\u52e2\u6aa2\u6e2c\u985e\u578b<\/h2>\n<p>\u5728 SwiftUI \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 <strong>Gesture<\/strong> \u4f86\u6aa2\u6e2c\u591a\u7a2e\u624b\u52e2\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>TapGesture<\/strong>\uff1a\u6aa2\u6e2c\u7528\u6236\u662f\u5426\u8f15\u89f8\u87a2\u5e55<\/li>\n<li><strong>LongPressGesture<\/strong>\uff1a\u6aa2\u6e2c\u7528\u6236\u662f\u5426\u9577\u6309\u87a2\u5e55<\/li>\n<li><strong>DragGesture<\/strong>\uff1a\u6aa2\u6e2c\u7528\u6236\u662f\u5426\u62d6\u66f3\u87a2\u5e55<\/li>\n<\/ul>\n<h2>\u57fa\u672c\u5be6\u4f5c\u7bc4\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4f7f\u7528 <strong>TapGesture<\/strong> \u7684\u57fa\u672c\u7bc4\u4f8b\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">struct ContentView: View {\n    var body: some View {\n        Text(\"Hello World\")\n            .onTapGesture {\n                print(\"Text tapped\")\n            }\n    }\n}\n<\/code><\/pre>\n<p>\u7576\u7528\u6236\u8f15\u89f8\u6587\u5b57\u6642\uff0c\u5c07\u5728\u63a7\u5236\u53f0\u8f38\u51fa &#8220;Text tapped&#8221;\u3002<\/p>\n<h2>\u9577\u6309\u624b\u52e2\u5be6\u4f5c\u7bc4\u4f8b<\/h2>\n<p>\u540c\u6a23\u5730\uff0c\u60a8\u4e5f\u53ef\u4ee5\u4f7f\u7528 <strong>LongPressGesture<\/strong>\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">struct ContentView: View {\n    var body: some View {\n        Text(\"Hello World\")\n            .onLongPressGesture {\n                print(\"Text long pressed\")\n            }\n    }\n}\n<\/code><\/pre>\n<p>\u9019\u6bb5\u4ee3\u78bc\u6703\u5728\u7528\u6236\u9577\u6309\u6587\u5b57\u6642\uff0c\u8f38\u51fa &#8220;Text long pressed&#8221;\u3002<\/p>\n<h2>\u62d6\u66f3\u624b\u52e2\u5be6\u4f5c\u7bc4\u4f8b<\/h2>\n<p>\u6b64\u5916\uff0c\u60a8\u9084\u53ef\u4ee5\u6aa2\u6e2c\u62d6\u66f3\u624b\u52e2\uff0c\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u7bc4\u4f8b\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">struct ContentView: View {\n    @State private var offset = CGSize.zero\n\n    var body: some View {\n        Text(\"Drag Me\")\n            .offset(offset)\n            .gesture(\n                DragGesture()\n                    .onChanged { value in\n                        self.offset = value.translation\n                    }\n                    .onEnded { _ in\n                        self.offset = .zero\n                    }\n            )\n    }\n}\n<\/code><\/pre>\n<p>\u9019\u6bb5\u4ee3\u78bc\u5141\u8a31\u7528\u6236\u62d6\u66f3\u6587\u5b57\uff0c\u4e26\u5728\u624b\u52e2\u7d50\u675f\u5f8c\u5c07\u5176\u91cd\u7f6e\u3002<\/p>\n<h2>\u932f\u8aa4\u6392\u9664\u8207\u6700\u4f73\u5be6\u8e10<\/h2>\n<p>\u5728\u5be6\u4f5c\u624b\u52e2\u6642\uff0c\u958b\u767c\u8005\u53ef\u80fd\u6703\u9047\u5230\u4e00\u4e9b\u5e38\u898b\u554f\u984c\uff1a<\/p>\n<ul>\n<li><strong>\u624b\u52e2\u885d\u7a81\uff1a<\/strong>\u5982\u679c\u591a\u500b\u624b\u52e2\u540c\u6642\u6fc0\u6d3b\uff0c\u53ef\u80fd\u6703\u5c0e\u81f4\u4e0d\u5982\u9810\u671f\u7684\u884c\u70ba\u3002\u78ba\u4fdd\u624b\u52e2\u7684\u512a\u5148\u7d1a\u6b63\u78ba\u8a2d\u5b9a\u3002<\/li>\n<li><strong>\u6027\u80fd\u554f\u984c\uff1a<\/strong>\u904e\u591a\u7684\u624b\u52e2\u6aa2\u6e2c\u53ef\u80fd\u5f71\u97ff\u61c9\u7528\u6027\u80fd\uff0c\u5efa\u8b70\u5728\u5fc5\u8981\u6642\u4f7f\u7528\u624b\u52e2\u3002<\/li>\n<\/ul>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u624b\u52e2\u6aa2\u6e2c\u4e0d\u50c5\u9650\u65bc\u7c21\u55ae\u7684\u8f38\u51fa\uff0c\u5b83\u9084\u53ef\u4ee5\u7528\u65bc\u5275\u5efa\u8907\u96dc\u7684\u4ea4\u4e92\uff0c\u4f8b\u5982\u62d6\u653e\u64cd\u4f5c\u3001\u5716\u5f62\u8b8a\u63db\u7b49\u3002\u60a8\u53ef\u4ee5\u9032\u4e00\u6b65\u63a2\u7d22\u9019\u4e9b\u61c9\u7528\uff0c\u589e\u5f37\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n<h2>\u5e38\u898b\u554f\u984c\u89e3\u7b54 (Q&#038;A)<\/h2>\n<h3>1. SwiftUI \u624b\u52e2\u6aa2\u6e2c\u80fd\u6aa2\u6e2c\u54ea\u4e9b\u985e\u578b\u7684\u624b\u52e2\uff1f<\/h3>\n<p>SwiftUI \u652f\u63f4\u591a\u7a2e\u624b\u52e2\u6aa2\u6e2c\uff0c\u5305\u62ec\u8f15\u89f8\u3001\u9577\u6309\u3001\u62d6\u66f3\u7b49\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u6839\u64da\u9700\u6c42\u9078\u64c7\u76f8\u61c9\u7684\u624b\u52e2\u3002<\/p>\n<h3>2. \u5982\u4f55\u8655\u7406\u591a\u500b\u624b\u52e2\u4e4b\u9593\u7684\u885d\u7a81\uff1f<\/h3>\n<p>\u5728 SwiftUI \u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 <strong>simultaneously<\/strong> \u6216 <strong>exclusive<\/strong> \u7b49\u624b\u52e2\u7d44\u5408\u4f86\u8655\u7406\u624b\u52e2\u4e4b\u9593\u7684\u885d\u7a81\u3002<\/p>\n<h3>3. \u6709\u54ea\u4e9b\u8cc7\u6e90\u53ef\u4ee5\u9032\u4e00\u6b65\u5b78\u7fd2 SwiftUI \u624b\u52e2\uff1f<\/h3>\n<p>\u5efa\u8b70\u53c3\u8003\u5b98\u65b9\u6587\u6a94\u548c\u591a\u500b\u6559\u5b78\u7db2\u7ad9\uff0c\u5982 <a href=\"https:\/\/www.raywenderlich.com\/567-swiftui-gestures-tutorial-getting-started\" target=\"_blank\" rel=\"noopener\">Ray Wenderlich<\/a> \u548c <a href=\"https:\/\/www.hackingwithswift.com\/quick-start\/swiftui\/how-to-detect-swipe-gestures-in-swiftui\" target=\"_blank\" rel=\"noopener\">Hacking with Swift<\/a>\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/SwiftUI-\u4e2d\u7684\u624b\u52e2\u6aa2\u6e2c_1676961619.104641.webp\" alt=\"SwiftUI \u4e2d\u7684\u624b\u52e2\u6aa2\u6e2c\" title=\"SwiftUI \u4e2d\u7684\u624b\u52e2\u6aa2\u6e2c\u793a\u4f8b\" width=\"1200\" height=\"628\" \/><br \/>\n&#8220;`<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981:SwiftUI\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u7684\u624b\u52e2\u6aa2\u6e2c\u529f\u80fd\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u8f15\u9b06\u5730\u6aa2\u6e2c\u7528\u6236\u7684\u624b\u52e2\uff0c\u4e26\u5c0d\u5176\u505a\u51fa\u53cd\u61c9\u3002\u672c\u6587\u5c07\u4ecb\u7d39SwiftUI\u4e2d\u7684\u624b\u52e2\u6aa2\u6e2c\u529f\u80fd\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u5b83\u5011\u4f86\u958b\u767ciOS\u61c9\u7528\u7a0b\u5e8f\u3002<\/p>\n","protected":false},"author":1,"featured_media":7719,"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-7720","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\/SwiftUI-\u4e2d\u7684\u624b\u52e2\u6aa2\u6e2c_1676961619.104641.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-20w","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7720","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=7720"}],"version-history":[{"count":2,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7720\/revisions"}],"predecessor-version":[{"id":13184,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7720\/revisions\/13184"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/7719"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=7720"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=7720"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=7720"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}