我需要制作一个可以垂直和水平滚动的 SwiftUI 视图,具有多个列,其中最左边的视图不能水平滚动,但下面的视图可以。
就像带有一些冻结标题列的电子表格一样思考。
我有一些工作,有点。GIF 显示,垂直滚动时会移动所有单元格,水平滚动时只会滚动“自定义”单元格。
但是,我还希望有一个冻结的标题行,就像 Mac 表格视图的列标题一样,它保持浮动在顶部,与下面的行的固定和水平滚动列对齐。我还没弄清楚这一点。
这是我的原型代码:
ScrollView {
ZStack(alignment: .leading) {
ScrollView (.horizontal) {
LazyVStack(spacing: 20) {
ForEach(0..<20) { row in
LazyHStack(spacing: 20) {
Text("")
.frame(width: 250, height: 200)
.background(Color.clear)
ForEach(0..<10) { column in
Text("Custom \(row), \(column)")
.foregroundColor(.white)
.font(.largeTitle)
.frame(width: 200, height: 200)
.background(Color.red)
}
}
}
}
}
VStack(spacing: 20) {
ForEach(0..<20) { row in
HStack(spacing: 2) {
Text("\(row)")
.foregroundColor(.yellow)
.font(.largeTitle)
.frame(width: 50, height: 200)
.background(Color.blue)
Text("Fixed \(row)")
.foregroundColor(.yellow)
.font(.largeTitle)
.frame(width: 200, height: 200)
.background(Color.blue)
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我是 SwiftUI 的新手,所以也许我错过了一些明显的东西。任何建议非常感谢!
| 归档时间: |
|
| 查看次数: |
1568 次 |
| 最近记录: |