更改高度限制未按预期工作

时间:2018-12-01 09:33:30

标签: ios autolayout

我有一个使用情节提要为其分配了恒定高度(200)的视图。 我还添加了一些约束,以使该视图停留在设备屏幕的底部。

我需要动态处理此视图的高度。 问题在于,当以编程方式更改高度限制时, 它没有粘在底部,就像视图在向上移动而不是在增加高度。

这是代码。我将其简化为专注于该问题:

class BottomSheetViewController: UIViewController {

    @IBOutlet weak var bottomSheetView: UIView!
    @IBOutlet weak var bottomSheetHeightConstraint: NSLayoutConstraint!

    func updateHeight() {
        bottomSheetHeightConstraint.constant = 400
        bottomSheetView.layoutIfNeeded()
    }

}

这是默认视图,并在调用updateHeight()之后:

enter image description here ===> enter image description here

这是所有使用的约束:

enter image description here

0 个答案:

没有答案
相关问题