![](/img/trans.png)
[英]How to make a view scrollable to view the full scene with sprites with Swift and SpriteKit?
[英]Scrollable full screen view swift
我希望在 Swift UI 中创建一个全屏可滚动视图。 我在将视图放入滚动视图和垂直堆栈后让视图全屏显示时遇到问题? 有什么建议?
这是我的代码的样子
struct ContentView : View {
var body: some View {
//var posts = [Post(postColor: .red), Post(postColor: .blue), Post(postColor: .green)]
ScrollView(.vertical, showsIndicators: false) {
VStack {
Post(postColor: .red)
Post(postColor: .blue)
Post(postColor: .green)
}
}
}
}
struct Post : View {
var postColor : Color
var body : some View {
VStack(alignment: .leading) {
HStack {
Text("Name")
.font(.title)
.fontWeight(.heavy)
Spacer()
}
Text("@Username")
.lineLimit(nil)
.font(.body)
Spacer()
}.background(postColor)
}
}
您可以使用GeometryReader
来实现这一点:
struct FullScreenViewsInScrollView: View {
var body: some View {
GeometryReader { geometry in
ScrollView {
VStack(spacing: 0) {
Rectangle()
.foregroundColor(.red)
.frame(height: geometry.size.height)
Rectangle()
.foregroundColor(.blue)
.frame(height: geometry.size.height)
Rectangle()
.foregroundColor(.green)
.frame(height: geometry.size.height)
}
}
}
}
}
结果应该是(我在实时预览中向下滚动了一点):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.