phvega
phvega

Reputation: 71

iOS navigation bar overlaps status bar on landscape dismiss

I have an app almost entirely built with Xcode Interface Builder and no code with the exception of the overrides of supportedInterfaceOrientations to fix the UIViewControllers orientation to either portrait or landscape. The app is composed of two view controllers:

When the button in the second view controller is pressed, the VC slides out of the window and once the animation is over the status bar appears over the navigation bar, partially overlapping it (NOTE: the layout fixes itself when the status is pressed). You can view the problem in the following video: https://imgur.com/FIBoszM

The following screenshots shows the "actual" (left) and "expected" (right) behaviours.

Actual Expected

Why is this happening?

Upvotes: 3

Views: 167

Answers (1)

Elmar
Elmar

Reputation: 4445

There are two possible solutions depending on your preferences.

  1. You can show/hide navigation bar visibility for your app by setting this boolean value true or false inside Info.plist file:
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
   
<key>UIStatusBarHidden</key>
<true/>
  1. You can control navigation bar appearance directly by using navigation bar's translucent property. That would fix the issue of the app view being framed underneath the navigation / status bar. You can use it like this:

self.navigationController.navigationBar.translucent = NO;

Or if you need to hide and then show it. You can use something like this:

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

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

For older iOS versions you may need to try something like this:

 if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
    self.edgesForExtendedLayout = UIRectEdgeNone;

Side Note: You may also need to check with Xcode that you are placed your app components inside Safe Area widget. That would prevent this issue without any further changes.

Upvotes: 0

Related Questions