我有物品清单。我如何滚动到列表 12。我可以使用几何阅读器来计算偏移量。但是如何滚动到这个偏移量?
List {
ForEach(0..<12) { index in
Text("...")
}
}
Run Code Online (Sandbox Code Playgroud)
Form Xcode 12,您可以转入 aScrollView然后您可以通过以下方式执行此操作.scrollTo(id):
var body: some View {
ScrollViewReader { scrollProxy in
ScrollView {
ForEach((1...100), id: \.self) { Text("\($0)") }
}
Button("Go!") {
withAnimation { scrollProxy.scrollTo(50) }
}
}
}
Run Code Online (Sandbox Code Playgroud)
注意 ScrollViewReader应该支持所有可滚动内容,但现在只支持ScrollView
| 归档时间: |
|
| 查看次数: |
1809 次 |
| 最近记录: |