ios 隐藏导航栏

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6544966/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 20:35:51  来源:igfitidea点击:

Hide navigation bar

objective-ciosuinavigationcontroller

提问by Kuldip

I have 3 views. (say 1st,2nd,3rd). I have pushed the 2nd view (which has a load view method) on the 1st. In the 2nd view I have created the 3rd using initWithFrame(which is inherited from UIWebView). In 2nd view I wrote self.view=3rd view.

我有 3 个观点。(比如第一、第二、第三)。我在 1 日推送了第二个视图(具有加载视图方法)。在第二个视图中,我创建了第三个视图initWithFrame(从 UIWebView 继承)。在第二个视图中,我写了 self.view=3rd 视图。

Now I want to hide the 2nd view's navigation bar in the 3rd view (i.e., when the user touch to 3rd view screen i.e. UIWebView). I got the touch recognition using gesture, but I can't hide the navigation bar.

现在我想在第三个视图中隐藏第二个视图的导航栏(即,当用户触摸到第三个视图屏幕时,即 UIWebView)。我使用手势进行了触摸识别,但无法隐藏导航栏。

3rd view don't support self.navigationController. And if I create 2nd view's object in 3rd, it does not hide the navigation bar. Can anybody help me?

第三种观点不支持self.navigationController。如果我在第三个视图中创建第二个视图的对象,它不会隐藏导航栏。有谁能够帮助我?

回答by Nabou

Ok. So you need to set the navigation bar to be hidden right after you create the navigation controller for that tab. You cannot adjust this after you push the view controller (as far as I know).

好的。因此,您需要在为该选项卡创建导航控制器后立即将导航栏设置为隐藏。按下视图控制器后,您无法调整它(据我所知)。

If you want the first view to not have a navigation bar at the top, then use this in your appDelegate where you initially declare your navigation controllers:

如果您希望第一个视图顶部没有导航栏,请在您最初声明导航控制器的 appDelegate 中使用它:

localNavigationController = [[UINavigationController alloc] initWithRootViewController:theViewController];
[localNavigationController setNavigationBarHidden:YES animated:YES];

If you want the views after that to be hidden, then you need a viewController for the subsequent views, and you will have to add

如果您希望隐藏之后的视图,那么您需要一个用于后续视图的 viewController,并且您必须添加

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

right before you call this:

在你打电话之前:

[[self navigationController] pushViewController:theThirdViewController animated:YES];

Hope this helps.

希望这可以帮助。

回答by Sisu

Implement this:

实现这个:

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

before assign the 3rd view. that is self.view = 3rd view

在分配第三个视图之前。那是 self.view = 3rd view

回答by KeithTheBiped

Note that the code must be added in the viewWillAppear method

注意代码一定要加在viewWillAppear方法中

-(void) viewWillAppear:(BOOL)animated
{
      self.navigationController.navigationBar.hidden = YES;
}

回答by Rahul Jamba

- (void)viewDidLoad 
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

     [[self navigationController] setNavigationBarHidden:YES animated:YES];
    //[self dismissViewControllerAnimated:YES completion:NULL];
}