方法一:
swift:
searchBar.heightAnchor.constraint(equalToConstant: 44).isActive = true
oc:
[searchBar.heightAnchor constraintEqualToConstant:44].active = YES;
方法二:
在Stack Overflow上找到了答案
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.view.setNeedsLayout() // force update layout
navigationController?.view.layoutIfNeeded() // to fix height of the navigation bar
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.view.setNeedsLayout() // force update layout
navigationController?.view.layoutIfNeeded() // to fix height of the navigation bar
}
方法二解决了我的问题