[英]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.