与 Geometry Reader 结合使用时,ScrollView 无法正确滚动(反弹)
Posted
技术标签:
【中文标题】与 Geometry Reader 结合使用时,ScrollView 无法正确滚动(反弹)【英文标题】:ScrollView doesn't scroll properly (bounces) in combination with Geometry Reader 【发布时间】:2020-11-11 13:47:15 【问题描述】:我已经在这里查看了答案 (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)
不幸的是,它没有正确滚动(反弹)并且总是回到顶部。你有什么想法吗?
谢谢!
【问题讨论】:
【参考方案1】:你只需要一个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)
【讨论】:
以上是关于与 Geometry Reader 结合使用时,ScrollView 无法正确滚动(反弹)的主要内容,如果未能解决你的问题,请参考以下文章
NetTopologySuite Geometry&WKT&WKB&GeoJSON互转