我试图隐藏并移除MainUIView的空间。我试图将MainUIViewheightConstarint设置为0。但它并没有隐藏其中的观点。
我想隐藏MainUIView中的所有视图和标签。
希望你能理解我的问题。提前谢谢你
这是我的密码

@IBOutlet weak var heightConstarint:NSLayoutConstraint!
//@IBOutlet weak var viewhide: UIView!
override func viewDidLoad() {
    super.viewDidLoad()
    heightConstarint.constant = 0
    //self.viewhide.setNeedsUpdateConstraints()
    self.view.layoutIfNeeded()
}

ios - 隐藏和删除嵌套UIView swift的所有空间-LMLPHP

最佳答案

更新约束在中永远不起作用
重写func viewDidLoad(){}
如果要以编程方式更改约束,则必须将代码放入
重写fun viewWillLayoutSubviews(){}
所以你的代码看起来

override func viewWillLayoutSubviews() {

     clipToBounds = true
     heightConstarint.constant = 0
     //self.viewhide.setNeedsUpdateConstraints()
     self.view.layoutIfNeeded()

}

10-08 02:28