您可以将其完全复制到操场上进行复制。当您启动它时,预览看起来不错,但是当您开始上下滚动时,项目(HStack)消失了。我不知道为什么...这是苹果的错误还是我的误解?
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
import SwiftUI
struct Cell : View {
var country: String
var body: some View {
VStack() {
Text("OMG").onAppear() { print ("OMG") }
ScrollView(.horizontal) {
HStack() {
Text(country)
}.background(Rectangle().fill(Color.blue))//.frame(height: 195)
}.background(Rectangle().fill(Color.orange))//.frame(height: 205)
}
}
}
struct ContentView: View {
var countries = ["a","b","c","d","e","f","g","h"]
init() {
UITableView.appearance().showsVerticalScrollIndicator = false
UITableView.appearance().showsHorizontalScrollIndicator = false
}
var body: some View {
GeometryReader() { geometry in
VStack() {
Text("Title")
List(self.countries,id: \.self) { country in
Cell(country: country)
}.environment(\.defaultMinListRowHeight,340)
}
}
}
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = UIHostingController(rootView: ContentView())