【发布时间】:2018-08-12 03:51:59
【问题描述】:
默认导航栏高度为 64。但将其方向更改为横向导航栏高度后更改为 28。我想在所有方向上设置固定导航栏大小。
【问题讨论】:
标签: ios swift uinavigationbar xcode9 ios-autolayout
默认导航栏高度为 64。但将其方向更改为横向导航栏高度后更改为 28。我想在所有方向上设置固定导航栏大小。
【问题讨论】:
标签: ios swift uinavigationbar xcode9 ios-autolayout
您可以添加方向观察器:
NotificationCenter.default.addObserver(self, selector: #selector(rotated), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
并添加旋转方法:
func rotated() {
let height: CGFloat = 50 //whatever height you want to add to the existing height
let bounds = self.navigationController!.navigationBar.bounds
self.navigationController?.navigationBar.frame = CGRect(x: 0, y: 0, width: bounds.width, height: bounds.height + height)
}
【讨论】: