Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation bar appear over the views with new iOS7 SDK

That’s not entirely true. There has been a new property introduced in iOS 7 that lets you adjust the layout behavior as in previous versions of iOS. Place this piece of code in your view controller, and you should be good to go! The space your navigation bar takes up should be accounted for automatically

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

You need add the above in your -(void)viewDidLoad method.

Note: You should be using the latest GM release of iOS 7 and Xcode 5 now since the API has changed from beta versions.


Screenshot from storyboard

If you are working in Storyboard (which I strongly recommend!) this is the solution: You can disable "Extend Edges" of your ViewController in storyboard. You have to do this for each viewController. You can disable extended edges by clicking the viewController icon in stortyboard (besides the productOwner beneath the view itself) and then selecting the attributes inspector (Like the images shows).

This will also set the alignment lines like iOS 6.

Another great tool in xCode 5 is "Preview": click on the butler Button (assistant editor) and select Preview. there you can select iOS 6 and see how your storyboard design will look like on iOS 6.

Its just great:D

[Update]

Be careful: disabling "Extend Edges" might result in a black glow on the navigation bar when the app enters background on iOS7. the glow will also be visible on the multitasking view (double press on home button). this can be solved by setting the background color of the navigation's bar view to white.

[self.navigationController.view setBackgroundColor:[UIColor whiteColor]];

As the OP says, there is a simple solution to this which is to set the navigation bar to be opaque. Rather than doing this in code, simply untick "Translucent" for your root navigation bar:

enter image description here


self.edgesForExtendedLayout=UIRectEdgeNone;

It works on iOS 7 simulator(Xcode 5 DP5)


these answers were all helpful, especially MQoder's, but for me i also had to set the default top bar to "opaque black navigation".

enter image description here


@One Man Crew's answer is correct, but:

I would recommend to use this code to avoid errors when running the app on older versions :

 #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1
     if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
        self.edgesForExtendedLayout = UIRectEdgeNone;
 #endif