How to change height of UIView that already has height anchor?

前端 未结 5 405

If I have this for a child view controller:

autoCompleteViewController.view.translatesAutoresizingMaskIntoConstraints = false
        NSLayoutConstraint.act         


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-13 13:41

    I've fixed it by implementing it like this:

    autoCompleteViewControllerHeight = NSLayoutConstraint( item: autoCompleteViewController.view, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 44.0) guard let autoCompleteViewControllerHeight = autoCompleteViewControllerHeight else { return } autoCompleteViewControllerHeight.isActive = true

    and then where it should be changed I added:

    let newHeight = calculateNewHeight() heightConstraintAutoCompleteViewController.constant = newHeight

    It works like a charm.

提交回复
热议问题