UINavigationBar / Status Bar Error in iOS7

Ultimate EDIT

(Instead of having too long a question with the changes making the final editing to clarify, see other changes if necessary).

Controller setup

I have an application that is configured as follows:

InitialViewController (subclass of ECSlidingViewController )

Main navigation controller (subclass of UINavigationController )

Main Home View Controller (subclass of UIViewController )




In the viewDidLoad element, I load the main navigation controller with the Home View controller as its root.

 self.topViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"MainNavVC"]; 



Problem

When you first load the application, the status bar and navigation bar are separated. enter image description here

This is the desired effect.

However, then I load the modal view controller and close it using standard methods:

 [self performSegueWithIdentifier:@"LoadSelectOpponentVC" sender:self]; 

Then close:

 [self dismissViewControllerAnimated:YES completion:nil]; 

This, in turn, leads to the fact that the main navigation controller (while holding the home view controller) incorrectly displays the status bar and overlaps:

enter image description here

Testing

  • The plist setting is set to YES - View controller-based status bar appearance
  • I tried setting edgesForExtendedLayout to the corresponding none, but no change.

entrance

I tried to output some frames to see where the problem occurred:

On first boot:

Main Nav VC - View Frame - {{0, 0}, {320, 480}}

 Main Nav VC - Nav Bar Frame - {{0, 0}, {320, 44}} Initial VC - View Frame - {{0, 0}, {320, 480}} Home VC - View Frame - {{0, 0}, {320, 480}} -- viewDidLoad Home VC Home VC - View Frame - {{0, 64}, {320, 416}} -- viewWillAppear Home VC --- After Modal is opened/closed ---- Home VC - View Frame - {{0, 64}, {320, 416}} -- viewWillAppear Home VC Main Nav VC - View Frame - {{0, 0}, {320, 480}} -- viewWillAppear Main Nav Main Nav VC - Nav Bar Frame - {{0, 20}, {320, 44}} -- viewWillAppear Main Nav Home VC - View Frame - {{0, 44}, {320, 436}} -- viewDidAppear Home VC 
+47
ios7 uinavigationcontroller uinavigationbar uistatusbar
Sep 22 '13 at 20:36
source share
15 answers

You have tried Apple’s recommendation regarding “Preventing the status bar from displaying your views”: https://developer.apple.com/library/content/qa/qa1797/_index.html

And you looked at "UIBarPositioningDelegate": https://developer.apple.com/documentation/uikit/uibarpositioningdelegate

+39
Sep 26 '13 at 4:58
source share

On iOS 7.0, the UIViewController works by default this way. The full screen will be viewed if you use the UIViewController inside the UINavigationController and the navigationBar displayed.

If a NavigationBar is displayed, do the following: ==>

 self.edgesForExtendedLayout = UIRectEdgeNone 

If the navigationBar is hidden, follow these steps: ==>

Adjust all UIView elements by moving 20 points

If you use the interface builder, you can use the iOS6 / 7 delta: firstly, “browse as iOS 6.0”, and then set the delta “20” to achieve a +20 offset in iOS 7

+26
Sep 26 '13 at 17:51
source share

I am surprised that no one hit the correct answer. UIBarPositioningDelegate works like a charm! Just make your UIBarPositioningDelegate view controller and assign it as a panel delegate. Place the bar 20 pixels on top. Then add this method to your view controller (only available in iOS7 +):

 - (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar { return UIBarPositionTopAttached; } 
+18
May 23 '14 at 14:18
source share

I had a similar problem with the hamburger menu button, which shifted the main view controller and had a menu controller on the side. I found that the menu controller’s navigation bar did not know whether the status bar is displayed or not. I fixed this by posting a notification when the status bar and hiddden were displayed, then doing

 [self.navigationController setNavigationBarHidden:YES/NO animated:NO]; 

in the menu manager.

+4
Oct 01 '13 at 3:43
source share

You tried to add the following code to your viewDidLoad method:

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

Apple quickly explains the switch to iOS 7 doumentation: https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/AppearanceCustomization.html

+3
Sep 25 '13 at 13:17
source share

I fixed this problem using the response from this post: iOS 7 | The navigation bar / toolbar buttons are very close to the status bar

Using Autolayout, you should ignore the installation of a new frame. You must add Top Space Constraint equal to 20 for TopBar for iOS 7.

+3
01 Oct '13 at
source share

I answered this length problem in this answer to a similar question . The short answer is: there is no way to get the automatic behavior of the status bar layout you’re used to from iOS 6 and earlier. You will have to design around it or find a way to mimic the old style (I cover both approaches).

I highly recommend that you do not manually tune to the navigation bar frame. Let the UINavigationController handle this on its own. Most likely, your problem is that your view of the navigation controller is not equal to the UIScreen restrictions.

+1
Sep 23 '13 at 18:08
source share

I know that you have a ViewController as the main VC. But if someone uses a UITableviewController and has the same problem, this code solves the problem:

 self.tableView.contentInset = UIEdgeInsetsMake(20.0f, 0.0f, 0.0f, 0.0f); 
+1
Dec 19 '14 at 12:34
source share

The solution to this is actually very simple. It involves manipulating the value of the UINavigationBar center.y , which uses UIKit to set the UINavigationBar to the height of the status bar. For simplicity, I subclassed the UINavigationBar and did the following:

 @implementation MyNavigationBar - (void) setCenter:(CGPoint)center { // Anything less than or equal to 22 is something we don't want (below SB height) if(center.y > 22) [super setCenter:center]; } @end 
0
Apr 12 '14 at 23:48
source share

Yes, the same problem. after all the steps, but no change.

I tried to work, making sure that AutoLayout is configured correctly for the entire screen, not only for the top view / toolbar, as indicated in

"Preventing the display of the status bar from your views": https://developer.apple.com/library/ios/qa/qa1797/_index.html

At least for all views just below the main Viewcontroller.view.

0
Apr 23 '14 at 15:00
source share

There is a built-in way to do this. Same as Joel Cave, but clarified:

Make your navigation bar with a Y-start of 20 points.

Then in the .h file:

 @interface XYZViewController : UIViewController <UIBarPositioningDelegate> 

And in the .m file:

 - (void)viewDidLoad { [super viewDidLoad]; self.navigationBar.delegate = self; } - (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar { return UIBarPositionTopAttached; } 
0
Jul 26 '14 at 6:19 06:19
source share

For me, the solution was to move the navigation bar by 20 points enter image description here

0
31 Oct '15 at 16:02
source share

I was a bit late for the party, but since I ran into the same problem and this was the first result that appeared in the search, I think that my answer could help other people :)

I fixed the problem by doing

 - (BOOL)shouldAutorotate { return NO; } 

in a view controller that represents a modal.

-one
Feb 26 '14 at 2:59
source share

Try it, all navigation panels should be translucent, disabled.

 [self.navigationController.navigationBar setTranslucent:NO]; 

If you designed your presentation using storyboards, you can solve the problem with Xcode. Select the NavigationBar widget and uncheck the Transparent box.

enter image description here

-one
Feb 26 '14 at 6:08
source share

the best way is to add this to the view in which you have a problem:

 if (self.navigationController.navigationBar.frame.origin.y==0) self.navigationController.navigationBar.frame = CGRectMake(self.navigationController.navigationBar.frame.origin.x, self.navigationController.navigationBar.frame.origin.y, self.navigationController.navigationBar.frame.size.width, 64); 
-2
Mar 12 '14 at 17:32
source share



All Articles