简体   繁体   English

滚动视图不滚动到顶部

[英]Scroll View not scrolling to top

As you can see from the video, when the code is built and ran, the Red View is 0px from the top edge. 从视频中可以看出,构建并运行代码时,红色视图距离上边缘为0px。 But after scrolling down and tapping the status bar to return to the top, there is a gap between the top of the screen and Red View (ie the black area). 但是在向下滚动并点击状态栏以返回到顶部之后,屏幕顶部和红色视图(即黑色区域)之间存在间隙。

GIF of Simulator 模拟器的GIF

What can I do to resolve the issue if the intended behaviour is for the Red View to be 0px from the top of display when the user scroll up to the very top? 如果用户向上滚动到顶部时,如果红色视图的预期行为是从显示顶部开始的0px,我该怎么办才能解决问题?

Try setting a minus value for the scrollviews content inset: 尝试为scrollviews内容插件设置减号:

scrollView.contentInset = UIEdgeInsets(top: -40, left: 0, bottom: 0, right: 0)

Your could also check the safe area. 您还可以检查安全区域。

This is a normal behavior in iOS. 这是iOS中的正常行为。 iOS will try to leave room for the status bar if you are using safe areas. 如果您使用安全区域,iOS将尝试为状态栏留出空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM