SwiftUI-细胞消失项目

SwiftUI-细胞消失项目,swiftui,Swiftui,您可以将其完全复制到游乐场进行复制。当您启动它时,预览看起来不错,但当您开始上下滚动时,项目(HStack)就会消失。我不知道为什么。。。这是苹果病毒还是我的误解 //: A UIKit based Playground for presenting user interface import UIKit import PlaygroundSupport import SwiftUI struct Cell : View { var country: String v

您可以将其完全复制到游乐场进行复制。当您启动它时,预览看起来不错,但当您开始上下滚动时,项目(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())

根据我的调查,问题在于使用ScrollView内部列表(可能是苹果的问题)。作为一个解决方案(或替代),您可以考虑用ScLoVIEW替换列表,如下所示(Cordon视图的主体,并且可以添加手动分隔符(),在这里,您希望具有类似的外观):


您是否在单个视图项目而不是游乐场上尝试了相同的代码?当然。以前就是这样(只是更复杂)-我把它分解为游乐场和简单的例子。确认不仅在游乐场,而且在Xcode预览、模拟器和Catalyst中复制
var body: some View {

    GeometryReader() { geometry in
        VStack() {
            Text("Title")
            ScrollView(.vertical) {
                ForEach(self.countries, id: \.self) { country in
                    Cell(country: country)
                        .frame(height: 340)
                }
            }
        }
    }
}