ScrollView 与 Geometry 结合使用时无法正确滚动(弹跳)Reader

ScrollView doesn't scroll properly (bounces) in combination with Geometry Reader

我已经在此处查看了答案 (ScrollView Doesn't Scroll with Geometry Reader as Child),我猜这很相似,但我无法弄明白。

我的目标是显示大小相同的图像(二次方)。

这是我的观点:


struct MyGeoView: View {
    
    let icons = ["bed.double.fill","tram.fill","tv.music.note.fill","hare.fill", "person", "clock", "plus", "trash", "home", "arrow", "pencil", "scribble", "folder", "folder.circle", "trash.circle", "paperplane"]
    
    var body: some View {
        
        GeometryReader{ geo in
            ScrollView{
                GeometryReader{ geo in
                    LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: 3), spacing: 3 ){
                        ForEach(icons, id: \.self){ post in
                            Image(systemName: post)
                                .frame(width: geo.size.width/3, height: geo.size.width/3)
                                .background(Color.pink)
                                .foregroundColor(.white)
                        }
                    }
                }
            }
        }
    }
    
}

不幸的是它没有正确滚动(弹跳)并且总是回到顶部。你有什么想法吗?

谢谢!

您只需要一个 GeometryReader,外部一个。

这是更正后的代码。使用 Xcode 12.1 / iOS 14.1

测试
var body: some View {
    GeometryReader{ geo in
        ScrollView{
            LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: 3), spacing: 3 ){
                ForEach(icons, id: \.self){ post in
                    Image(systemName: post)
                        .frame(width: geo.size.width/3, height: geo.size.width/3)
                        .background(Color.pink)
                        .foregroundColor(.white)
                }
            }
        }
    }
}