UIScrollView ContentView动态高度限制 [英] UIScrollView ContentView dynamic height constraints

查看:133
本文介绍了UIScrollView ContentView动态高度限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正面临contentView高度限制的问题.所有标签都具有动态高度,即没有固定高度.我读过某处将高度设置为等于scrollview高度.

I am facing issue with contentView height constraints. All labels have dynamic height i.e no fixed height. I have read somewhere to set height equal to scrollview height.

ViewController的高度当前为870px,scrollview的高度为757px.我不知道如何在AutoLayout中设置高度,因为我无法在特定点之后滚动.

The height of ViewController is currently 870px, scrollview height is 757px. I have no idea how can i set height in AutoLayout , as I am unable to scroll after a certain point.

我先设置了UIScrollView,然后添加了UIView作为UIScrollView的子级,然后添加了2个UIImageView和几个UILabel,UILabel的大小取决于内容,并且内容不固定.由于UIView的高度是静态的,所以当UILabel的内容很大时,在某个点之后我将无法滚动.

I have set UIScrollView first then I added UIView as the child of the UIScrollView then I added 2 UIImageView and few UILabels, the size of UILabel is dependant on the content and content is not fixed. Since the height of UIView is static, when the content of UILabel is quite big, then I am unable to scroll after a certain point.

按照@Wonder Dog的回答,我进行了一些更改,现在我得到了Scroll View高度不明确的问题

As per @Wonder Dog answer I made few changes, now I am getting Scroll View ambiguous height issue

推荐答案

以这种方式执行:

  1. 将滚动视图添加到视图控制器,并且不对其设置任何约束.
  2. 开始在滚动视图中添加子视图(图像,标签等)并设置所需的约束.对于标签,您无需设置高度,因为它们会根据内容自动调整高度.对于其他子视图,还设置高度或其他约束,这些约束以后将确定高度(即长宽比).如果滚动视图对于要添加的所有子视图来说都太小,请从其底部拖动以增加其高度.将所有子视图保留在滚动视图中并将它们彼此链接起来很重要.
  3. 对于滚动视图中的最后一个标签,在滚动视图中添加一个底部约束.
  4. 从滚动视图到主视图(顶部,顶部,底部和尾部)添加边距约束.

由于所有子视图均已链接并固定在滚动视图内的顶部和底部,并且滚动视图固定在情节提要的视图上,因此可以使用.

Since all subviews are chained and pinned to top and bottom inside the scroll view and the scroll view is pinned to the storyboard's view, this will work.

请勿设置滚动视图的高度.将其设置为757 px是错误的,因为它将在高度低于757 px的设备上在屏幕下方呈现滚动视图.

Do not set the height of the scroll view. Setting it to 757 px is wrong because it renders your scroll view below the screen on devices with a height lower than 757px.

这篇关于UIScrollView ContentView动态高度限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆