动态设置滚动视图的内容大小不起作用

时间:2018-03-18 10:03:05

标签: ios swift uiscrollview

-ViewController
--View
---ScrollView
----View
-----TextView
-----Label
-----etc

我想通过以下方式设置 UIScrollView contentSize

let lastView : UIView! = scrollView.subviews.last
let height = lastView.frame.size.height
let pos = lastView.frame.origin.y
let sizeOfContent = height + pos

scrollView.contentSize.height = sizeOfContent

但是,它不起作用。有什么建议吗?

1 个答案:

答案 0 :(得分:2)

首先,你必须提供滚动视图约束,例如top to superview,导致superview,bottom to superview,trailing to superview。

然后提供scrollview的子视图,称为视图约束,如scrollview,trailing,bottom和top约束。

然后提供scrollview的子视图,称为视图约束,如相等宽度和相等高度的主视图。

并将最后提供的约束等高度优先级更改为251。

这应该使scrollview动态地改变内容。

试试!!!

相关问题