无GPU环境下深度学习实战:CPU训练方案与PyTorch配置全指南
2026/10/7 17:04:57
对于信息流式内容和设置风格的行,使用List,此时内置的行复用、选择和可访问性很重要。
List。Section标题对相关行分组。ScrollViewReader。.listStyle(.plain)。.listStyle(.grouped)。.scrollContentBackground(.hidden)+ 自定义背景。.listRowInsets(...)和.listRowSeparator(.hidden)调整行间距和分隔线。.environment(\\.defaultMinListRowHeight, ...)控制紧凑列表布局。@MainActorstructTimelineListView:View{@Environment(\.selectedTabScrollToTop)privatevarselectedTabScrollToTop@StateprivatevarscrollToId:String?varbody:someView{ScrollViewReader{proxyinList{ForEach(items){iteminTimelineRow(item:item).id(item.id).listRowInsets(.init(top:12,leading:16,bottom:6,trailing:16)).listRowSeparator(.hidden)}}.listStyle(.plain).environment(\\.defaultMinListRowHeight,1).onChange(of:scrollToId){_,newValueinifletnewValue{proxy.scrollTo(newValue,anchor:.top)scrollToId=nil}}.onChange(of:selectedTabScrollToTop){_,newValueinifnewValue==0{withAnimation{proxy.scrollTo(ScrollToView.Constants.scrollToTop,anchor:.top)}}}}}}@MainActorstructSettingsView:View{varbody:someView{List{Section("General"){NavigationLink("Display"){DisplaySettingsView()}NavigationLink("Haptics"){HapticsSettingsView()}}Section("Account"){Button("Sign Out",role:.destructive){}}}.listStyle(.insetGrouped)}}List。.contentShape(Rectangle())。.refreshable。List行内使用重型自定义布局;改用ScrollView+LazyVStack。List和嵌套的ScrollView;可能导致手势冲突。