重新创建高度约束

时间:2019-01-03 22:37:09

标签: swift snapkit

所以我有一个按钮,我想用它来切换视图的高度。这意味着我不能使用优先级来更新这些值。但是,当我在表格中点击时,它会正确更新。

let shown = false;
tableHeaderView.snp.makeConstraints { make in
        make.width.equalTo(self.tableView.snp.width)
        make.height.equalTo(50)
    }
filterButton.rx.tap.subscribe(onNext: {
    self.tableHeaderView.snp.updateConstraints { make in
            if (shown) {
                make.height.equalTo(50)
            } else {
                make.height.equalTo(100)
            }
            self.shown.toggle()
    }
})

此代码打破了我要添加的约束。如何避免这种情况?

(
    "<SnapKit.LayoutConstraint:0x600002574780@AthleteSearchController.swift#54 UIView:0x7fccf0441c20.height == 100.0>",
    "<NSLayoutConstraint:0x600002235db0 'UIView-Encapsulated-Layout-Height' UIView:0x7fccf0441c20.height == 50   (active)>"
)

Will attempt to recover by breaking constraint 
<SnapKit.LayoutConstraint:0x600002574780@AthleteSearchController.swift#54 UIView:0x7fccf0441c20.height == 100.0>

0 个答案:

没有答案