【发布时间】:2021-09-12 01:04:28
【问题描述】:
我正在尝试将滚动视图中的内容 Text("Test.....") 设置为顶部。不使用 .frame (maxHeight: 150) 等。我只需要在 Text ("123")) 下启动它,但没有任何结果。并且在各个方向滚动时应该可以工作。这只是一个示例,以了解如何从技术上进行操作。可以帮忙的人!
import SwiftUI
struct MainView: View {
var body: some View {
NavigationView {
content
}
.padding()
}
}
private extension MainView {
var content: some View {
VStack {
ZStack(alignment: .topLeading) {
ScrollView([.vertical, .horizontal]) {
Text("TestTestTestTestTestTestTestTestTestTestTest")// set to top in content
.frame(height: 100)
.background(Color.green)
//.position(y: 0)
}
Text("123")
}
.background(Color.blue)
}
}
}
【问题讨论】:
-
Spacer() 不能帮你填满空间吗?
标签: ios scroll swiftui scrollview zstack