最佳答案
尝试这种方式,此代码用于 navigation bar
而不是 navigation controller
。可能是你没有设置Constraint或者互相冲突
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator){
super.viewWillTransition(to: size, with: coordinator)
var frame: CGRect = (self.navigationController?.navigationBar.frame)!
coordinator.animate(alongsideTransition: { (UIViewControllerTransitionCoordinatorContext) -> Void in
let orient = UIApplication.shared.statusBarOrientation
switch orient {
case .portrait:
frame.size.height = 44
frame.size.width = self.view.frame.width
default:
frame.size.height = 32
frame.size.width = self.view.frame.width
}
}, completion: { (UIViewControllerTransitionCoordinatorContext) -> Void in
print("rotation completed")
self.navigationController?.navigationBar.frame = frame
})
}
关于ios - 横向模式下的 UINavigationBar 高度未完全显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42862371/