简体   繁体   English

Scrollview不会一直向下滚动

[英]Scrollview won't scroll all the way down

I have a scroll view which works fine. 我有一个滚动视图,可以正常工作。 Almost. 几乎。 I'm building in Any/Any. 我在任何/任何建筑物中。 The problem is that the scroll view won't scroll past the view controller. 问题是滚动视图将不会滚动通过视图控制器。 I have a switch that is mostly in the view controller window, but the rest is off the box (not really sure how to describe it; it's in the view in the scroll view, but the view is longer than the view controller so part of it is hidden). 我有一个开关,该开关主要在视图控制器窗口中,但其余开关均处于关闭状态(不确定如何描述它;它在滚动视图中的视图中,但是视图比视图控制器长,因此属于它是隐藏的)。

The scroll view will scroll down until it hits the part where the view controller would end if you were looking at it in Xcode. 滚动视图将向下滚动,直到到达用Xcode查看视图控制器将结束的部分为止。 There is some more stuff under the switch (labels and another switch). 开关下还有更多东西(标签和另一个开关)。 To view these you have to forcefully scroll down. 要查看这些内容,您必须强制向下滚动。 Xcode shows no constraint errors (little red circle with white arrow). Xcode没有显示任何约束错误(带有白色箭头的红色小圆圈)。

Hopefully this makes sense 希望这有道理

A ScrollView needs to know the height and width of the content it is holding in order to know how much to scroll and which direction. ScrollView需要知道它所容纳内容的高度和宽度,以便知道要滚动多少以及向哪个方向滚动。 Here is a quick read on how ScrollViews work in iOS: https://www.objc.io/issues/3-views/scroll-view/ 这是有关ScrollViews如何在iOS中工作的快速阅读: https : //www.objc.io/issues/3-views/scroll-view/

You can set this programmatically using the contentSize property, but this requires you to know and or calculate the contentSize , which is pretty tedious in most cases. 您可以使用contentSize属性以编程方式进行设置,但这需要您知道和/或计算contentSize ,这在大多数情况下非常繁琐。

The correct way of defining the contentSize in iOS is to define AutoLayout constraints in your View. 在iOS中定义contentSize的正确方法是在View中定义AutoLayout约束。 Here is an excellent tutorial on doing just that: https://www.natashatherobot.com/ios-autolayout-scrollview/ 这是有关此操作的出色教程: https : //www.natashatherobot.com/ios-autolayout-scrollview/

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

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