How to prevent UINavigationBar from covering top of view in iOS 7?

IosObjective CIos7UinavigationbarUistatusbar

Ios Problem Overview


After updating to Xcode 5, the navigation bars in all of my app's views have shifted down. Here are some screenshots, the first showing everything in the view as it's pulled down, and the second showing all of it untouched. The search bar should begin where the navigation bar.

All Content All Content on Idle

Anyone know how I can fix this?

edit: i have tried this previously recommendation:

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

But it yields very odd results.

Solution Attempt

This may be because I have a "slide menu" under this view controller that is appearing due to the transparency of the navigation bar.

Ios Solutions


Solution 1 - Ios

Set the navigation bar's translucent property to NO:

self.navigationController.navigationBar.translucent = NO;

This will fix the view from being framed underneath the navigation bar and status bar.

If you have to show and hide the navigation bar, then use

 if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
    self.edgesForExtendedLayout = UIRectEdgeNone;   // iOS 7 specific

in your viewDidLoad method.

Solution 2 - Ios

In iOS 7 by defaults all Controller translucent property value is YES, so you set translucent property NO for this issue.

self.navController.navigationBar.translucent = NO;

Solution 3 - Ios

You can disable the "Extend edges" in Attribute inspector of View Controller of this screen (as shown in below image) :

enter image description here

Solution 4 - Ios

This works for swift as well on iOS 8.1

navigationController?.navigationBar.translucent = false

Solution 5 - Ios

If you want to keep the translucency on your navigationBar, at the end of your viewDidLoad or in your viewWillAppear add this line of code:

[self.view sendSubviewToBack:self.tableView]

Somehow if your scrollView subclass (UITableView, UICollectionView, etc.) is at index 0 in your current view subviews, it will automatically adjust the insets according to your navigationBar. And it shouldn't affect your UI in versions prior to iOS7 either.


EDIT If you initialize your UITableView programmatically, then it is best to add it to the view using this [self.view insertSubview:self.tableView atIndex:0];

Solution 6 - Ios

Swift 4:

Set following line of code in viewDidLoad method:

self.navigationController?.navigationBar.isTranslucent = false

Solution 7 - Ios

You can add this method into your view controller as shown on this URL:

-(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    self.searchBar.frame = 
    CGRectMake(0, self.topOfViewOffset, self.searchBar.frame.size.width, self.searchBar.frame.size.height);
}

Solution 8 - Ios

Another approach is to set self.automaticallyAdjustsScrollViewInsets = YES; on your view controller. This is enabled by default. But in your case:

I see you are using EGORefreshHeaderView. It plays with contentInset of UITableView. So when you release it, header will reset top inset instead of restore previous value.

Solution 9 - Ios

If you want to have complete control on views and avoid faulty adjustments of iOS, subclass UITableView and adjust the insets (both scroll and indicators) in -(void)willMoveToWindow:(UIWindow *)newWindow. Works for me.

Solution 10 - Ios

Another option is to open your Info.plist file in source code mode and enter the following info:

<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>UIStatusBarHidden</key>
<true/>

Hope this helps.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSam D20View Question on Stackoverflow
Solution 1 - IosDeepeshView Answer on Stackoverflow
Solution 2 - IosSumit MundraView Answer on Stackoverflow
Solution 3 - IosAchyut SagarView Answer on Stackoverflow
Solution 4 - Iosuplearned.comView Answer on Stackoverflow
Solution 5 - IosjbouazizView Answer on Stackoverflow
Solution 6 - IosMd. Najmul HasanView Answer on Stackoverflow
Solution 7 - IosmalkotyView Answer on Stackoverflow
Solution 8 - IosKrivoblotskyView Answer on Stackoverflow
Solution 9 - IosFarhad MalekpourView Answer on Stackoverflow
Solution 10 - IosNicoliView Answer on Stackoverflow