I want to recalculate the height constraint when the phone orientation changes. I'm using the functions uninstall()
and install()
to make this happen. However, it's not working as desired. Am I using them incorrectly?
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()
}
}