xcode 滚动视图不垂直滚动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42701165/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
scroll view not scrolling vertically
提问by S.M_Emamian
回答by matt
You're using constraints in your scroll view, so the content size is determined by the constraints, not by setting the contentSize
in code. You need to fix your constraints so that they size the content from the inside outof the scroll view. The top subview of the scrollview needs to be pinned to the scrollview's top, and the bottom subview needs to be pinned to the scrollview's bottom, and all the views in between need to be pinned to one another, in such a way as to dictate the desired content size height. But the scroll view itselfneeds to be pinned to its superview, so that it is not taller than the screen. In other words, this will work when the sum of the constrained heights insidethe scroll view is greater than the constrained height ofthe scroll view.
您在滚动视图中使用约束,因此内容大小由约束决定,而不是通过设置contentSize
in 代码。您需要修复您的约束,以便它们从滚动视图的内向外调整内容的大小。滚动视图的顶部子视图需要固定到滚动视图的顶部,底部子视图需要固定到滚动视图的底部,并且两者之间的所有视图都需要相互固定,以指示所需的内容大小高度。但是滚动视图本身需要固定在它的超级视图上,这样它就不会比屏幕高。换句话说,当滚动视图内的约束高度总和大于约束高度时,这将起作用的滚动视图。
回答by Jagdeep Singh
Problem is in constraints. Follow these steps:
问题在于约束。按着这些次序:
Add a container view in scroll view and set top, bottom, leading and trailing constraints of container view with scroll view. Do not set height of this container view. add other views in this container view. Height of container view will adjusted according to sub views of container view. Height of sub views of container view should not set proportional to container view, it should set proportional to scroll view.
在滚动视图中添加容器视图,并使用滚动视图设置容器视图的顶部、底部、前导和尾随约束。不要设置此容器视图的高度。在此容器视图中添加其他视图。容器视图的高度将根据容器视图的子视图进行调整。容器视图的子视图高度不应与容器视图成比例,而应与滚动视图成比例。
Also make sure you have set the top and bottom of container view to its sub view
还要确保您已将容器视图的顶部和底部设置为其子视图