{"id":7718,"date":"2025-06-02T14:45:52","date_gmt":"2025-06-05T07:09:51","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=7718"},"modified":"2025-06-05T14:45:52","modified_gmt":"2025-06-05T07:09:51","slug":"https-badgameshow-com-steven-502","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-502\/","title":{"rendered":"\u5728 SwiftUI \u4e2d\u4f7f\u7528\u9375\u76e4\u7684\u6700\u4f73\u5be6\u8e10\u8207\u65b0\u6280\u8853\uff082025 \u6700\u65b0\u7248\uff09"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"swift, SwiftUI, \u9375\u76e4, \u4f7f\u7528\u9375\u76e4, \u9375\u76e4\u4e8b\u4ef6, SwiftUI \u6559\u5b78\"><\/p>\n<h1>\u5728 SwiftUI \u4e2d\u4f7f\u7528\u9375\u76e4\u7684\u6700\u4f73\u5be6\u8e10\u8207\u65b0\u6280\u8853\uff082025 \u6700\u65b0\u7248\uff09<\/h1>\n<p>SwiftUI \u662f Apple \u5728 WWDC 2019 \u63a8\u51fa\u7684\u65b0\u6846\u67b6\uff0c\u65e8\u5728\u5e6b\u52a9\u958b\u767c\u8005\u5feb\u901f\u958b\u767c\u73fe\u4ee3\u5316\u7684 iOS \u61c9\u7528\u7a0b\u5f0f\u3002\u96a8\u8457 SwiftUI \u7684\u4e0d\u65b7\u66f4\u65b0\uff0c\u4f7f\u7528\u9375\u76e4\u4f86\u63a7\u5236\u61c9\u7528\u7684\u884c\u70ba\u5df2\u6210\u70ba\u4e00\u9805\u91cd\u8981\u529f\u80fd\uff0c\u9019\u4e0d\u50c5\u80fd\u63d0\u5347\u4f7f\u7528\u8005\u9ad4\u9a57\uff0c\u9084\u80fd\u8b93\u64cd\u4f5c\u66f4\u52a0\u9ad8\u6548\u3002<\/p>\n<h2>\u5982\u4f55\u5728 SwiftUI \u4e2d\u4f7f\u7528\u9375\u76e4<\/h2>\n<p>\u5728 SwiftUI \u4e2d\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 <strong>onKeyCommand<\/strong> \u4f86\u63a7\u5236\u9375\u76e4\u4e8b\u4ef6\u3002\u9019\u500b\u65b9\u6cd5\u63a5\u53d7\u4e00\u500b <strong>KeyboardShortcut<\/strong> \u7684\u53c3\u6578\uff0c\u8b93\u958b\u767c\u8005\u53ef\u4ee5\u6307\u5b9a\u5728\u6309\u4e0b\u7279\u5b9a\u6309\u9375\u6642\u89f8\u767c\u76f8\u61c9\u7684\u884c\u70ba\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u4e0b\u9762\u7684\u7bc4\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u5728\u6309\u4e0b <strong>Command + S<\/strong> \u6642\u57f7\u884c\u5132\u5b58\u64cd\u4f5c\uff1a<\/p>\n<pre><code>onKeyCommand(KeyboardShortcut(key: .s, modifiers: [.command])) {\n    \/\/ \u57f7\u884c\u5132\u5b58\u7684\u884c\u70ba\n    print(\"\u6a94\u6848\u5df2\u5132\u5b58\")\n}\n<\/code><\/pre>\n<h2>\u5728 SwiftUI \u4e2d\u63a7\u5236\u9375\u76e4\u7684\u884c\u70ba<\/h2>\n<p>\u9664\u4e86 <strong>onKeyCommand<\/strong>\uff0cSwiftUI \u4e5f\u63d0\u4f9b\u4e86 <strong>onKeyboardShortcut<\/strong> \u4f86\u9032\u884c\u66f4\u7d30\u7dfb\u7684\u9375\u76e4\u4e8b\u4ef6\u8655\u7406\u3002\u9019\u540c\u6a23\u63a5\u53d7\u4e00\u500b <strong>KeyboardShortcut<\/strong> \u7684\u53c3\u6578\uff0c\u7528\u65bc\u6307\u5b9a\u6309\u4e0b\u7684\u6309\u9375\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u53e6\u4e00\u500b\u7bc4\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528 <strong>onKeyboardShortcut<\/strong> \u4f86\u5be6\u73fe\u5feb\u901f\u5132\u5b58\u7684\u529f\u80fd\uff1a<\/p>\n<pre><code>onKeyboardShortcut(KeyboardShortcut(key: .s, modifiers: [.command])) {\n    \/\/ \u57f7\u884c\u5132\u5b58\u7684\u884c\u70ba\n    print(\"\u6a94\u6848\u5df2\u5132\u5b58\")\n}\n<\/code><\/pre>\n<h2>\u932f\u8aa4\u6392\u9664<\/h2>\n<p>\u5728\u4f7f\u7528\u9375\u76e4\u4e8b\u4ef6\u6642\uff0c\u958b\u767c\u8005\u53ef\u80fd\u6703\u9047\u5230\u4e00\u4e9b\u5e38\u898b\u7684\u932f\u8aa4\uff0c\u4f8b\u5982\uff1a<\/p>\n<p>&#8211; **\u672a\u80fd\u89f8\u767c\u4e8b\u4ef6**\uff1a\u8acb\u78ba\u8a8d\u4e8b\u4ef6\u7d81\u5b9a\u662f\u5426\u6b63\u78ba\uff0c\u6aa2\u67e5 <strong>KeyboardShortcut<\/strong> \u7684\u8a2d\u5b9a\u3002<br \/>\n&#8211; **\u591a\u91cd\u7d81\u5b9a**\uff1a\u78ba\u4fdd\u4e0d\u6703\u6709\u591a\u500b\u8996\u5716\u540c\u6642\u76e3\u807d\u540c\u4e00\u500b\u9375\u76e4\u4e8b\u4ef6\uff0c\u9019\u53ef\u80fd\u6703\u5c0e\u81f4\u4e8b\u4ef6\u672a\u88ab\u6b63\u78ba\u8655\u7406\u3002<\/p>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u9664\u4e86\u57fa\u672c\u7684\u9375\u76e4\u4f7f\u7528\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u5c07\u9375\u76e4\u4e8b\u4ef6\u8207\u5176\u4ed6 SwiftUI \u5143\u4ef6\u7d50\u5408\uff0c\u5275\u5efa\u66f4\u8c50\u5bcc\u7684\u4e92\u52d5\u3002\u4f8b\u5982\uff1a<\/p>\n<p>&#8211; \u4f7f\u7528\u9375\u76e4\u5feb\u901f\u5c0e\u822a\uff1a\u5728\u591a\u500b\u8996\u5716\u9593\u901a\u904e\u9375\u76e4\u5feb\u6377\u9375\u5feb\u901f\u5207\u63db\u3002<br \/>\n&#8211; \u7d50\u5408\u8868\u55ae\u8f38\u5165\uff1a\u5728\u8868\u55ae\u4e2d\u4f7f\u7528\u9375\u76e4\u4e8b\u4ef6\u4f86\u5be6\u73fe\u5373\u6642\u9a57\u8b49\u6216\u81ea\u52d5\u5b8c\u6210\u3002<\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u5728 SwiftUI \u4e2d\uff0c\u900f\u904e <strong>onKeyCommand<\/strong> \u548c <strong>onKeyboardShortcut<\/strong>\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u9748\u6d3b\u5730\u63a7\u5236\u9375\u76e4\u4e8b\u4ef6\uff0c\u63d0\u5347\u61c9\u7528\u7684\u4f7f\u7528\u9ad4\u9a57\u3002\u96a8\u8457 SwiftUI \u7684\u66f4\u65b0\uff0c\u6301\u7e8c\u5b78\u7fd2\u6700\u65b0\u7684\u9375\u76e4\u4f7f\u7528\u6280\u5de7\u5c07\u6709\u52a9\u65bc\u589e\u5f37\u61c9\u7528\u7684\u4e92\u52d5\u6027\u3002<\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<h3>Q1: SwiftUI \u4e2d\u7684\u9375\u76e4\u4e8b\u4ef6\u5982\u4f55\u8207\u5176\u4ed6 UI \u5143\u4ef6\u7d50\u5408\u4f7f\u7528\uff1f<\/h3>\n<p>A1: \u958b\u767c\u8005\u53ef\u4ee5\u5c07\u9375\u76e4\u4e8b\u4ef6\u8207\u5404\u7a2e SwiftUI \u5143\u4ef6\uff08\u5982 List\u3001Form \u7b49\uff09\u7d50\u5408\uff0c\u6839\u64da\u4f7f\u7528\u8005\u7684\u64cd\u4f5c\u52d5\u614b\u66f4\u65b0\u4ecb\u9762\u6216\u57f7\u884c\u7279\u5b9a\u529f\u80fd\u3002<\/p>\n<h3>Q2: \u5982\u4f55\u5728 SwiftUI \u4e2d\u81ea\u5b9a\u7fa9\u9375\u76e4\u5feb\u6377\u9375\uff1f<\/h3>\n<p>A2: \u4f7f\u7528 <strong>KeyboardShortcut<\/strong> \u65b9\u6cd5\uff0c\u53ef\u4ee5\u81ea\u5b9a\u7fa9\u4efb\u4f55\u6309\u9375\u8207\u4fee\u98fe\u9375\u7684\u7d44\u5408\uff0c\u4e26\u5c07\u5176\u8207\u5c0d\u61c9\u7684\u884c\u70ba\u7d81\u5b9a\u3002<\/p>\n<h3>Q3: \u5982\u679c\u9375\u76e4\u4e8b\u4ef6\u6c92\u6709\u53cd\u61c9\uff0c\u6211\u8a72\u600e\u9ebc\u8fa6\uff1f<\/h3>\n<p>A3: \u9996\u5148\u6aa2\u67e5\u4e8b\u4ef6\u7d81\u5b9a\u662f\u5426\u6b63\u78ba\uff0c\u78ba\u4fdd\u9375\u76e4\u5feb\u6377\u9375\u6c92\u6709\u8207\u5176\u4ed6\u529f\u80fd\u6c96\u7a81\uff0c\u4e26\u78ba\u8a8d\u8996\u5716\u7684\u529f\u80fd\u6027\u662f\u5426\u6b63\u5e38\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/\u5728-SwiftUI-\u4e2d\u4f7f\u7528\u9375\u76e4_1676961530.0206468.webp\" alt=\"\u5728 SwiftUI \u4e2d\u4f7f\u7528\u9375\u76e4\" title=\"SwiftUI \u9375\u76e4\u4f7f\u7528\u3001SwiftUI \u9375\u76e4\u529f\u80fd\u3001SwiftUI \u9375\u76e4\u7a0b\u5f0f\u78bc\u3001SwiftUI \u9375\u76e4\u61c9\u7528\u3001SwiftUI \u9375\u76e4\u6280\u8853\" width=\"1200\" height=\"628\"\/><br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728SwiftUI\u4e2d\u4f7f\u7528\u9375\u76e4\uff0c\u8b93\u958b\u767c\u8005\u53ef\u4ee5\u66f4\u8f15\u9b06\u5730\u5efa\u7acb\u4f7f\u7528\u8005\u4ecb\u9762\uff0c\u4e26\u63d0\u4f9b\u66f4\u591a\u7684\u529f\u80fd\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0eSwiftUI\u4e2d\u7684\u9375\u76e4\u529f\u80fd\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u5be6\u7528\u7684\u7a0b\u5f0f\u78bc\u7bc4\u4f8b\uff0c\u8b93\u958b\u767c\u8005\u53ef\u4ee5\u66f4\u8f15\u9b06\u5730\u4f7f\u7528\u9375\u76e4\u3002<\/p>\n","protected":false},"author":1,"featured_media":7717,"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-7718","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\/\u5728-SwiftUI-\u4e2d\u4f7f\u7528\u9375\u76e4_1676961530.0206468.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-20u","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7718","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=7718"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7718\/revisions"}],"predecessor-version":[{"id":13197,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7718\/revisions\/13197"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/7717"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=7718"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=7718"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=7718"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}