SwiftUI - 使用 ScrollView 和嵌套视图偏移会导致滚动问题

SwiftUI - Using ScrollView and nested views offset leads to a scroll issue

此代码运行完美,我可以滚动到最底部的图片:

ScrollView {

                Image("MountainWelcomBackground").resizable().frame(height: 300)

                Image("MountainWelcomBackground").resizable().frame(height: 300)

                Image("MountainWelcomBackground").resizable().frame(height: 300)

                Image("MountainWelcomBackground").resizable().frame(height: 300)

                Image("MountainWelcomBackground").resizable().frame(height: 300)



            }.edgesIgnoringSafeArea(.top)

但如果我将此代码与偏移量一起使用:

ScrollView {

                    Image("MountainWelcomBackground").resizable().frame(height: 300)

                    Image("MountainWelcomBackground").resizable().frame(height: 300).offset(y: 500)

我无法滚动到底部,只能看到弹跳效果将我滚动回顶部。

Effect is here on the video

View.offset 不改变视图布局,只在屏幕上绘制演示文稿,所以 content/size 滚动视图没有改变,它像以前一样滚动

不清楚你的真正目标,但可能的解决方案是使用改变布局的工具,例如最简单的是

Image("MountainWelcomBackground").resizable().frame(height: 300)
    .padding(.top, 500)