Reputation: 235
I used UINavigationBar and when I change to landscape mode the bar look like this .
in portrait mode
Upvotes: 1
Views: 1879
Reputation: 10600
Try this way and this code for navigation bar
not navigation controller
. may be you missing to set Constraint or conflict each other
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
})
}
Upvotes: 4