Sam
Sam

Reputation: 235

UINavigationBar height in landscape mode does not appear fully

I used UINavigationBar and when I change to landscape mode the bar look like this .

enter image description here

in portrait mode

enter image description here

Upvotes: 1

Views: 1879

Answers (1)

Nazmul Hasan
Nazmul Hasan

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

Related Questions