Swift - 滚动视图和安全区域的布局问题

发布于 2025-01-16 18:39:38 字数 850 浏览 4 评论 0原文

我对可滚动布局有疑问 我有两个 UiViewController :

一个在顶部,带有绿色背景(TopVC),另一个是红色(初始 VC),它们完全可滚动

当我启动应用程序时,我遇到了这个布局问题:我看到另一个 VC 的底部(绿色的)。

输入图片这里的描述

当我开始滚动时,这个布局问题消失了,我可以上下滚动而不会出现任何布局问题。(正如您所看到的,SafeAreaView 按预期覆盖了整个屏幕)

有人吗知道如何解决这个问题以便从正确的布局开始吗?

感谢

您提供信息,我已经测试过的项目:(github项目链接)

在此处输入图像描述

修复:

if let top
        = UIApplication.shared.windows.first?.safeAreaInsets.top
    {
        scrollView.contentInset.top = -top
    }

I have a problem with a scrollable layout
I have two UiViewController :

One on the top with a green background (TopVC) and the other is red (the initial VC) which are perfectly scrollable

When I start the app, I have this layout problem : I see the bottom of the other VC(the green one).

enter image description here

When I start to scroll, this layout problem dissapear and I can scroll up and down without any layout problem.( as you can see the SafeAreaView covers the entire screen as expected )

Does someone know how I can fix that in order to start with a correct layout ?

Thanks

For info, the project that I have tested :(link of the github project)

enter image description here

Fixed with :

if let top
        = UIApplication.shared.windows.first?.safeAreaInsets.top
    {
        scrollView.contentInset.top = -top
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文