xcode 我已经添加了两个网格项目,但我只能看到一个网格出现

93ze6v8z  于 2023-08-07  发布在  其他
关注(0)|答案(1)|浏览(96)
let Columns: [GridItem] = [
    GridItem(.flexible(), spacing: nil, alignment: nil),
    GridItem(.flexible(), spacing: nil, alignment: nil),

]
var body: some View {

    LazyVGrid(columns: /*@START_MENU_TOKEN@*//*@PLACEHOLDER=Columns@*/[GridItem(.fixed(200))]/*@END_MENU_TOKEN@*/) {
        ScrollView{
            ForEach(0..<20) { index in
                Rectangle()
                    .frame(height:150)
                                }
       
        }

    }
}

字符串
我期望两个矩形,但我只能看到一个出现在屏幕上

oyt4ldly

oyt4ldly1#

试试这个,把ScrollView放在LazyVGrid之前:

struct LazyView: View {
    
    let Columns: [GridItem] = [
        GridItem(.flexible(), spacing: nil, alignment: nil),
        GridItem(.flexible(), spacing: nil, alignment: nil)
    ]
    
    var body: some View {
        ScrollView {  // <--- here
            LazyVGrid(columns: Columns) {
                ForEach(0..<20) { index in
                    Rectangle().foregroundColor(Color.red).frame(height:150)
                }
            }
        }
    }
}

字符串

相关问题