10

I have a minor trouble hiding the navigationBar for my UINavigationController

I have added:

self.navigation!.navigationBar.hidden = true

This, unfortunately leaves some kind of background (white) left behind the white status bar that pushes the content (green) downwards, and an unwanted scroll behaviour where I can drag the content up and down to show/hide the white background. What I need is for the statusbar to take up no vertical space what so ever and lay on top of the content (green)

How do I achieve this? Answers in swift as well obj-c are very welcome

enter image description here EDIT: I have tried various versions of the following, the problem remains -.-

override func loadView() {
    self.view = UIView(frame:UIScreen.mainScreen().bounds)
    self.view.backgroundColor = UIColor.whiteColor()


    self.navigation = UINavigationController(rootViewController: self.guideViewController!)

    self.navigation!.navigationBarHidden = true
    self.navigation!.setNavigationBarHidden(true, animated: true)

    self.view.addSubview(self.navigation!.view)
}

override func viewDidLoad() {
    self.automaticallyAdjustsScrollViewInsets = false
    self.navigation!.automaticallyAdjustsScrollViewInsets = false
}

EDIT 2:

printing:

UIApplication.sharedApplication().statusBarFrame.size.height

after viewDidLoad returns 20

4
  • Whats "!" IN > self.navigation!.navigationBar.hidden = true ? Commented Sep 17, 2014 at 9:39
  • 1
    It just means to unwrap an optional value, a variable that isn't set when it's defined is optional and needs to be unwrapped when requested Commented Sep 17, 2014 at 10:02
  • How do you set your views contraints ? Commented Sep 17, 2014 at 10:17
  • Edited my edit to show the view constraints Commented Sep 17, 2014 at 11:25

5 Answers 5

9

Updated :

Just add this in you ViewDidLoad method

self.automaticallyAdjustsScrollViewInsets = NO;
Sign up to request clarification or add additional context in comments.

1 Comment

I falsely believed the issue was occurring in my UINavigationController, after some looking i realised the fault lied in one of my pushed views, adding automaticallyAdjustsScrollViewInsets in the view did the trick! Thanks iBhavin
6

You can use hide navigation bar like

[self.navigationController setNavigationBarHidden:YES];

Hide status bar

// Hide status bar iOS 7 or later
- (BOOL)prefersStatusBarHidden
{
    return YES;
}

Comments

1

Look at this site: https://developer.xamarin.com/recipes/ios/content_controls/navigation_controller/make_the_nav_bar_disappear/

This site says that "The behavior is slightly different depending on whether the Nav Bar is opaque or translucent"

I hope it is helpful.

Comments

0
[self.navigationController setNavigationBarHidden:YES animated:animated];

Comments

0

I know the question has already been answered but I was having the same issue when hiding a navigation bar then using a UIScrollView in the view.

I fixed it programmatically using:

self.edgesForExtendedLayout = UIRectEdgeNone;

Or in interface builder by deselecting all of these: enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.