iOS - UINavigationController, Hide navigationBar

老子叫甜甜 提交于 2019-12-21 08:17:23

问题


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

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


回答1:


Updated :

Just add this in you ViewDidLoad method

self.automaticallyAdjustsScrollViewInsets = NO;



回答2:


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;
}



回答3:


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.




回答4:


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



回答5:


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:



来源:https://stackoverflow.com/questions/25887009/ios-uinavigationcontroller-hide-navigationbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!