{"id":190871,"date":"2022-06-15T03:29:49","date_gmt":"2022-06-14T19:29:49","guid":{"rendered":"https:\/\/www.idc.net\/help\/190871\/"},"modified":"2022-06-15T03:29:49","modified_gmt":"2022-06-14T19:29:49","slug":"%e5%90%8e%e6%b5%aa%e4%ba%91ios%e6%95%99%e7%a8%8b%ef%bc%9a%e4%b8%ba%e4%bd%a0%e7%9a%84%e5%86%85%e5%ae%b9%e9%80%89%e6%8b%a9%e5%ae%b9%e5%99%a8%e8%a7%86%e5%9b%be","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/190871\/","title":{"rendered":"\u540e\u6d6a\u4e91IOS\u6559\u7a0b\uff1a\u4e3a\u4f60\u7684\u5185\u5bb9\u9009\u62e9\u5bb9\u5668\u89c6\u56fe"},"content":{"rendered":"<h2> \u6982\u89c8 <\/h2>\n<p> SwiftUI \u63d0\u4f9b\u5e7f\u6cdb\u7684\u5bb9\u5668\u89c6\u56fe\uff0c\u7528\u4e8e\u89c6\u56fe\u7684\u5206\u7ec4\u548c\u91cd\u590d\u3002\u4e00\u4e9b\u5bb9\u5668\u4e13\u7528\u4e8e\u6253\u9020\u7ed3\u6784\u548c\u5e03\u5c40\uff0c\u4f8b\u5982 Stack \u89c6\u56fe\u3001\u60f0\u6027 Stack \u89c6\u56fe\u548c Grid \u89c6\u56fe\u3002\u53e6\u4e00\u4e9b\u5bb9\u5668\uff0c\u4f8b\u5982 List \u548c Form\uff0c\u4e5f\u91c7\u7528\u7cfb\u7edf\u6807\u51c6\u7684\u89c6\u89c9\u6548\u679c\u548c\u4ea4\u4e92\u3002 <\/p>\n<p> \u4e3a App \u7528\u6237\u754c\u9762\u7684\u6bcf\u4e2a\u90e8\u5206\u9009\u62e9\u6700\u5408\u9002\u7684\u5bb9\u5668\u89c6\u56fe\uff0c\u662f\u4e00\u9879\u9700\u8981\u5b66\u4e60\u7684\u91cd\u8981\u6280\u80fd\uff1b\u4ece\u786e\u5b9a\u76f8\u90bb\u4e24\u4e2a\u89c6\u56fe\u7684\u4f4d\u7f6e\uff0c\u5230\u4f7f\u7528\u6570\u767e\u79cd\u5143\u7d20\u521b\u5efa\u590d\u6742\u7684\u5e03\u5c40\uff0c\u5b83\u80fd\u5728\u65b9\u65b9\u9762\u9762\u4e3a\u4f60\u63d0\u4f9b\u5e2e\u52a9\u3002 <\/p>\n<h3> \u5bf9\u89c6\u56fe\u96c6\u5408\u8fdb\u884c\u5206\u7ec4 <\/h3>\n<p> Stack \u89c6\u56fe\u662f SwiftUI \u4e2d\u6700\u539f\u59cb\u7684\u5e03\u5c40\u5bb9\u5668\u3002\u5229\u7528 Stack \u53ef\u4ee5\u5c06\u89c6\u56fe\u96c6\u5408\u6309\u6c34\u5e73\u7ebf\u6216\u5782\u76f4\u7ebf\u5206\u7ec4\uff0c\u6216\u5c06\u89c6\u56fe\u76f8\u4e92\u53e0\u653e\u3002 <\/p>\n<p> \u4f7f\u7528 <code>HStack<\/code> (\u82f1\u6587) \u53ef\u4ee5\u5c06\u89c6\u56fe\u7f6e\u4e8e\u6c34\u5e73\u7ebf\u4e0a\uff0c\u4f7f\u7528 <code>VStack<\/code> (\u82f1\u6587) \u53ef\u4ee5\u5c06\u89c6\u56fe\u7f6e\u4e8e\u5782\u76f4\u7ebf\u4e0a\uff0c\u800c\u4f7f\u7528 <code>ZStack<\/code> (\u82f1\u6587) \u5219\u53ef\u4ee5\u5c06\u89c6\u56fe\u76f8\u4e92\u53e0\u653e\u3002\u7136\u540e\uff0c\u5408\u5e76 Stack \u89c6\u56fe\u4ee5\u6784\u5efa\u66f4\u4e3a\u590d\u6742\u7684\u5e03\u5c40\u3002\u8fd9\u4e09\u79cd Stack \u53ca\u5176\u5bf9\u9f50\u548c\u95f4\u9694\u5c5e\u6027\u3001\u89c6\u56fe\u4fee\u9970\u7b26\u4e0e <code>Spacer<\/code> (\u82f1\u6587) \u89c6\u56fe\u76f8\u7ed3\u5408\uff0c\u53ef\u4ee5\u5b9e\u73b0\u6781\u5927\u7684\u5e03\u5c40\u7075\u6d3b\u6027\u3002 <\/p>\n<\/p>\n<p> \u4f60\u901a\u5e38\u4f7f\u7528 Stack \u89c6\u56fe\u4f5c\u4e3a\u5176\u4ed6\u5bb9\u5668\u89c6\u56fe\u4e2d\u7684\u6784\u5efa\u5757\u3002\u4f8b\u5982\uff0c<code>List<\/code> (\u82f1\u6587) \u901a\u5e38\u5305\u542b Stack \u89c6\u56fe\uff0c\u4f60\u7528\u5b83\u6765\u5e03\u7f6e\u6bcf\u884c\u4e2d\u7684\u89c6\u56fe\u3002 <\/p>\n<p> \u6709\u5173\u4f7f\u7528 Stack \u89c6\u56fe\u5e03\u7f6e\u89c6\u56fe\u7684\u66f4\u591a\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605\u201c\u4f7f\u7528 Stack \u89c6\u56fe\u6784\u5efa\u5e03\u5c40\u201d\u3002 <\/p>\n<h3> \u91cd\u590d\u89c6\u56fe\u6216\u89c6\u56fe\u7ec4 <\/h3>\n<p> \u4f60\u8fd8\u53ef\u4ee5\u4f7f\u7528 <code>HStack<\/code> (\u82f1\u6587)\u3001<code>VStack<\/code> (\u82f1\u6587)\u3001<code>LazyHStack<\/code> (\u82f1\u6587) \u548c <code>LazyVStack<\/code> (\u82f1\u6587) \u6765\u91cd\u590d\u89c6\u56fe\u6216\u89c6\u56fe\u7ec4\u3002\u5728 <code>ScrollView<\/code> (\u82f1\u6587) \u4e2d\u653e\u7f6e\u4e00\u4e2a Stack \u89c6\u56fe\uff0c\u8fd9\u6837\u4f60\u7684\u5185\u5bb9\u4fbf\u53ef\u4ee5\u6269\u5c55\u5230\u5176\u5bb9\u5668\u7684\u8fb9\u754c\u4e4b\u5916\u3002\u7528\u6237\u53ef\u4ee5\u540c\u65f6\u6c34\u5e73\u6eda\u52a8\u3001\u5782\u76f4\u6eda\u52a8\u6216\u53cc\u5411\u6eda\u52a8\u3002 <\/p>\n<p> \u5806\u6808\u89c6\u56fe\u548c\u60f0\u6027\u5806\u6808\u5177\u6709\u76f8\u4f3c\u7684\u529f\u80fd\uff0c\u53ef\u80fd\u7ed9\u4eba\u611f\u89c9\u5b83\u4eec\u80fd\u591f\u4e92\u6362\uff0c\u4f46\u662f\uff0c\u5b83\u4eec\u5728\u4e0d\u540c\u60c5\u51b5\u4e0b\u6709\u5404\u81ea\u7684\u4f18\u52bf\u3002\u5806\u6808\u89c6\u56fe\u4f1a\u4e00\u6b21\u6027\u8f7d\u5165\u6240\u6709\u5b50\u89c6\u56fe\uff0c\u5e03\u5c40\u6027\u80fd\u5feb\u4e14\u53ef\u9760\uff0c\u56e0\u4e3a\u7cfb\u7edf\u5728\u8f7d\u5165\u6bcf\u4e2a\u5b50\u89c6\u56fe\u65f6\u5c31\u77e5\u9053\u5b83\u4eec\u7684\u5927\u5c0f\u548c\u5f62\u72b6\u3002\u60f0\u6027\u5806\u6808\u4f1a\u4e3a\u4e86\u6027\u80fd\u800c\u635f\u5931\u4e00\u5b9a\u7a0b\u5ea6\u7684\u5e03\u5c40\u6b63\u786e\u6027\uff0c\u539f\u56e0\u662f\u7cfb\u7edf\u4ec5\u5728\u5b50\u89c6\u56fe\u53ef\u89c1\u65f6\u624d\u4f1a\u8ba1\u7b97\u5b83\u4eec\u7684\u51e0\u4f55\u7ed3\u6784\u3002 <\/p>\n<\/p>\n<p> \u5728\u9009\u62e9\u8981\u4f7f\u7528\u7684\u5806\u6808\u89c6\u56fe\u7c7b\u578b\u65f6\uff0c\u8bf7\u59cb\u7ec8\u5148\u9009\u62e9\u6807\u51c6\u5806\u6808\u89c6\u56fe\uff0c\u5e76\u4e14\u4ec5\u5728\u5bf9\u4ee3\u7801\u8fdb\u884c\u6027\u80fd\u5206\u6790\u540e\u8bc1\u660e\u503c\u5f97\u63d0\u5347\u6027\u80fd\u65f6\uff0c\u624d\u5e94\u5207\u6362\u5230\u60f0\u6027\u5806\u6808\u3002\u6709\u5173\u60f0\u6027\u5806\u6808\u89c6\u56fe\u4ee5\u53ca\u5982\u4f55\u8861\u91cf App \u7684\u89c6\u56fe\u8f7d\u5165\u6027\u80fd\u7684\u66f4\u591a\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605\u201c\u521b\u5efa\u9ad8\u6027\u80fd\u7684\u53ef\u6eda\u52a8\u5806\u6808\u201d\u3002 <\/p>\n<h3> \u5728\u4e8c\u7ef4\u5e03\u5c40\u4e2d\u653e\u7f6e\u89c6\u56fe <\/h3>\n<p> \u8981\u540c\u65f6\u4ee5\u6c34\u5e73\u65b9\u5f0f\u548c\u5782\u76f4\u65b9\u5f0f\u5e03\u7f6e\u89c6\u56fe\uff0c\u8bf7\u4f7f\u7528 <code>LazyVGrid<\/code> (\u82f1\u6587) \u6216 <code>LazyHGrid<\/code> (\u82f1\u6587)\u3002\u82e5\u8981\u5e03\u7f6e\u81ea\u7136\u663e\u793a\u5728\u6b63\u65b9\u5f62\u5bb9\u5668\u4e2d\u7684\u5185\u5bb9 (\u4f8b\u5982\uff0c\u56fe\u50cf\u56fe\u5e93)\uff0c\u7f51\u683c\u662f\u4e00\u4e2a\u975e\u5e38\u597d\u7684\u5bb9\u5668\u9009\u62e9\u3002\u53e6\u5916\uff0c\u82e5\u8981\u653e\u5927\u7528\u6237\u754c\u9762\u5e03\u5c40\u4ee5\u5728\u8f83\u5927\u7684\u8bbe\u5907\u4e0a\u663e\u793a\uff0c\u7f51\u683c\u4e5f\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\u3002\u4f8b\u5982\uff0c\u8054\u7cfb\u4fe1\u606f\u76ee\u5f55\u53ef\u80fd\u9002\u5408\u4ee5\u5217\u8868\u6216\u5782\u76f4\u5806\u6808\u7684\u5f62\u5f0f\u663e\u793a\u5728 iPhone \u4e0a\uff0c\u4f46\u662f\uff0c\u5982\u679c\u5c06\u76ee\u5f55\u653e\u5927\u4ee5\u5728\u66f4\u5927\u7684\u8bbe\u5907 (\u4f8b\u5982 iPad \u6216 Mac) \u4e0a\u663e\u793a\u65f6\uff0c\u91c7\u7528\u7f51\u683c\u5e03\u5c40\u7684\u5f62\u5f0f\u53ef\u80fd\u66f4\u81ea\u7136\u3002 <\/p>\n<\/p>\n<p> \u4e0e\u5806\u6808\u89c6\u56fe\u4e00\u6837\uff0cSwiftUI \u7f51\u683c\u89c6\u56fe\u5e76\u4e0d\u5305\u542b\u56fa\u6709\u7684\u6eda\u52a8\u89c6\u53e3\uff1b\u5982\u679c\u76f8\u5173\u5185\u5bb9\u53ef\u80fd\u8d85\u51fa\u53ef\u7528\u7684\u7a7a\u95f4\uff0c\u5e94\u5c06\u5b83\u4eec\u7f6e\u4e8e\u4e00\u4e2a <code>ScrollView<\/code> (\u82f1\u6587) \u4e2d\u3002 <\/p>\n<h3> \u663e\u793a\u6570\u636e\u96c6\u5e76\u4e0e\u4e4b\u4ea4\u4e92 <\/h3>\n<p> SwiftUI \u4e2d\u7684 <code>List<\/code> (\u82f1\u6587) \u89c6\u56fe\u5728\u6982\u5ff5\u4e0a\u4e0e <code>LazyVStack<\/code> (\u82f1\u6587) \u548c <code>ScrollView<\/code> (\u82f1\u6587) \u7684\u7ec4\u5408\u7c7b\u4f3c\uff0c\u4f46\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u4f1a\u5728\u5185\u5bb9\u5143\u7d20\u4e4b\u95f4\u548c\u5468\u56f4\u5e94\u7528\u9002\u5408\u5e73\u53f0\u7684\u89c6\u89c9\u6837\u5f0f\u3002\u4f8b\u5982\uff0c\u5728 iOS \u4e0a\u8fd0\u884c\u65f6\uff0c<code>List<\/code> (\u82f1\u6587) \u7684\u9ed8\u8ba4\u914d\u7f6e\u4f1a\u5728\u5404\u884c\u4e4b\u95f4\u6dfb\u52a0\u5206\u9694\u7ebf\uff0c\u5e76\u4e14\u5982\u679c List \u5305\u542b\u5728 <code>NavigationView<\/code> (\u82f1\u6587) \u91cc\uff0c\u5b83\u4f1a\u7ed9\u5177\u6709\u5bfc\u822a\u529f\u80fd\u7684\u5185\u5bb9\u5143\u7d20\u7ed8\u5236\u8be6\u60c5\u6307\u793a\u7b26\u3002 <\/p>\n<p> <code>List<\/code> (\u82f1\u6587) \u89c6\u56fe\u8fd8\u652f\u6301\u4e3a\u5e38\u89c1\u4efb\u52a1 (\u4f8b\u5982\uff0c\u63d2\u5165\u3001\u91cd\u65b0\u6392\u5e8f\u548c\u79fb\u9664\u9879\u76ee) \u63d0\u4f9b\u4e0e\u5e73\u53f0\u76f8\u5bf9\u5e94\u7684\u4ea4\u4e92\u3002\u4f8b\u5982\uff0c\u901a\u8fc7\u5c06 <code>onDelete(perform:)<\/code> (\u82f1\u6587) \u4fee\u9970\u7b26\u6dfb\u52a0\u5230 <code>List<\/code> (\u82f1\u6587) \u4e2d\u7684 <code>ForEach<\/code> (\u82f1\u6587)\uff0c\u53ef\u4ee5\u5b9e\u73b0\u7cfb\u7edf\u6807\u51c6\u7684\u8f7b\u626b\u4ee5\u5220\u9664\u4ea4\u4e92\u3002 <\/p>\n<p> \u4e0e <code>LazyHStack<\/code> (\u82f1\u6587) \u548c <code>LazyVStack<\/code> (\u82f1\u6587) \u4e00\u6837\uff0cSwiftUI <code>List<\/code> (\u82f1\u6587) \u4e2d\u7684\u884c\u4e5f\u4f1a\u4ee5\u60f0\u6027\u65b9\u5f0f\u8f7d\u5165\uff0c\u6ca1\u6709\u5bf9\u5e94\u7684\u975e\u60f0\u6027\u8f7d\u5165\u65b9\u5f0f\u3002List \u672c\u8eab\u4f1a\u5728\u5fc5\u8981\u65f6\u6eda\u52a8\uff0c\u4f60\u4e0d\u9700\u8981\u5c06\u5b83\u4eec\u5305\u88c5\u5728 <code>ScrollView<\/code> (\u82f1\u6587) \u4e2d\u3002 <\/p>\n<h3> \u4e3a\u6570\u636e\u8f93\u5165\u7ec4\u5408\u89c6\u56fe\u548c\u63a7\u4ef6 <\/h3>\n<p> \u4f7f\u7528 <code>Form<\/code> (\u82f1\u6587) \u53ef\u4ee5\u7ec4\u5408\u7cfb\u7edf\u6807\u51c6\u63a7\u4ef6\uff0c\u6784\u5efa\u6570\u636e\u8f93\u5165\u754c\u9762\u3001\u8bbe\u7f6e\u6216\u504f\u597d\u8bbe\u7f6e\u7a97\u53e3\u3002 <\/p>\n<\/p>\n<p> \u4e0e\u6240\u6709 SwiftUI \u89c6\u56fe\u4e00\u6837\uff0c\u8868\u5355\u4ee5\u5e73\u53f0\u9002\u7528\u7684\u65b9\u5f0f\u663e\u793a\u5176\u5185\u5bb9\u3002\u8bf7\u6ce8\u610f\uff0c<code>Form<\/code> (\u82f1\u6587) \u4e2d\u7684\u63a7\u4ef6\u5e03\u5c40\u53ef\u80fd\u56e0\u5e73\u53f0\u4e0d\u540c\u800c\u5b58\u5728\u5f88\u5927\u7684\u5dee\u5f02\u3002\u4f8b\u5982\uff0c\u5728 iOS \u4e0a\uff0c<code>Form<\/code> (\u82f1\u6587) \u4e2d\u7684 <code>Picker<\/code> (\u82f1\u6587) \u63a7\u4ef6\u4f1a\u6dfb\u52a0\u5bfc\u822a\uff0c\u4ece\u800c\u5728\u5355\u72ec\u5c4f\u5e55\u4e0a\u663e\u793a\u9009\u62e9\u5668\u7684\u9009\u9879\uff0c\u800c\u5728 macOS \u4e0a\uff0c\u540c\u4e00\u4e2a <code>Picker<\/code> (\u82f1\u6587) \u63a7\u4ef6\u4f1a\u663e\u793a\u5f39\u51fa\u5f0f\u6309\u94ae\u6216\u4e00\u7ec4\u5355\u9009\u6309\u94ae\u3002 <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u89c8 SwiftUI \u63d0\u4f9b\u5e7f\u6cdb\u7684\u5bb9\u5668\u89c6\u56fe\uff0c\u7528\u4e8e\u89c6\u56fe\u7684\u5206\u7ec4\u548c\u91cd\u590d\u3002\u4e00\u4e9b\u5bb9\u5668\u4e13\u7528\u4e8e\u6253\u9020\u7ed3\u6784\u548c\u5e03\u5c40\uff0c\u4f8b\u5982 Stack [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":190872,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[189686],"tags":[],"class_list":["post-190871","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ios"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/190871","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=190871"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/190871\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media\/190872"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=190871"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=190871"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=190871"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}