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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 09:49:59  来源:igfitidea点击:

scroll view not scrolling vertically

iosxcodeuiscrollviewautolayout

提问by S.M_Emamian

I have a scroll view that it not scrolling at all:

我有一个滚动视图,它根本不滚动:

enter image description here

在此处输入图片说明



enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

    scroll_view_content_a_job.contentSize.height = 1800
    scroll_view_content_a_job.isScrollEnabled = true

回答by matt

You're using constraints in your scroll view, so the content size is determined by the constraints, not by setting the contentSizein 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.

您在滚动视图中使用约束,因此内容大小由约束决定,而不是通过设置contentSizein 代码。您需要修复您的约束,以便它们滚动视图的内向外调整内容的大小。滚动视图的顶部子视图需要固定到滚动视图的顶部,底部子视图需要固定到滚动视图的底部,并且两者之间的所有视图都需要相互固定,以指示所需的内容大小高度。但是滚动视图本身需要固定在它的超级视图上,这样它就不会比屏幕高。换句话说,当滚动视图的约束高度总和大于约束高度时,这将起作用滚动视图。

回答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

还要确保您已将容器视图的顶部和底部设置为其子视图