Mahi Tej Gvp
Mahi Tej Gvp

Reputation: 1034

Prevent View Controller from extending under status bar

I have a view controller which is the rootVc for Navigation Controller.

I needed the navigation bar to be hiddden for the rootview controller hence I used the following method to hide it and make it reappear.

override func viewWillAppear(_ animated: Bool) {
    self.navigationController?.setNavigationBarHidden(true, animated: false)
}

 override func viewWillDisappear(_ animated: Bool) {
    self.navigationController?.setNavigationBarHidden(false, animated: false)
}

I'm basically hiding the navigation bar in the rootVc and showing it for all other view controllers.

But when I remove the NavBar I see that my content is extending under the status bar

Is there a way to fix this?

enter image description here

Upvotes: 1

Views: 645

Answers (1)

Manoj
Manoj

Reputation: 1069

Instead of setting the top constraint to superView use safe area. Something like this

enter image description here

Upvotes: 2

Related Questions