3
我想在手機方向更改時重新計算高度約束。我正在使用函數uninstall()
和install()
來實現此目的。但是,它不能按需要工作。我是否錯誤地使用它們?重新計算方向變化時的SnapKit約束
class ActionOverlayViewController: UIViewController {
private var tableView = UITableView()
private var heightConstraint: Constraint?
override func viewDidLoad() {
super.viewDidLoad()
tableView.snp_makeConstraints { make in
self.heightConstraint = make.height.lessThanOrEqualTo(UIScreen.mainScreen().bounds.size.height).priorityHigh().constraint
make.height.equalTo(242).priorityLow()
}
}
override func updateViewConstraints() {
tableView.snp_updateConstraints { make in
self.heightConstraint.uninstall()
self.heightConstraint.install()
}
super.updateViewConstraints()
}
override func traitCollectionDidChange(previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
updateViewConstraints()
}
}