在我的应用程序中使用ContainerView,其中包含以下内容
在某些情况下,我必须隐藏视图,tableview。通过以下设置,我可以显示具有动态高度的容器视图
view.translatesAutoresizingMaskIntoConstraints = false
UITableView
contentSize
观察员通过改变tableview高度。但是在这里我无法获得containerView内容的动态高度。
我尝试过以下选项来获取容器视图内容高度,但没有运气
containerView.frame.size.height
containerView.bounds.size.height
stackView.frame.size.height
stackView.bounds.size.height
setNeedsLayout()
,stackViewlayoutIfNeeded()
,stackViewoverride func viewDidLayoutSubviews()
,override func viewWillLayoutSubviews()
中获得containsView,stackView高度终于找到了答案,下面是实现解决方案的步骤
>= 0
。stackView.setNeedsLayout(), stackView.layoutIfNeeded()