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

问题描述 投票:0回答:1

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

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

uiscrollview swiftui
1个回答
0
投票
[View.offset不会更改视图布局,只更改屏幕上的图形显示,因此滚动视图的内容/大小不会更改,并且像以前一样滚动]

尚不清楚您的真实目标,但可能的解决方案是使用更改布局的工具,例如,最简单的方法是

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

© www.soinside.com 2019 - 2024. All rights reserved.