如何从一个特定的视图控制器隐藏导航栏

我创build了一个两个闪屏iPhone应用程序。 之后用户被带到第一个视图。 我已经添加了一个UINavigationController。 它工作得很好。

如何单独删除打开视图的导航栏?

主窗口

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.splashScreen = [[SplashScreen alloc] initWithNibName:@"SplashScreen" bundle:nil]; if (self.pageController == nil) { openingpage *page=[[openingpage alloc]initWithNibName:@"openingpage" bundle:[NSBundle mainBundle]]; self.pageController = page; [page release]; } [self.navigationController pushViewController:self.pageController animated:YES]; [window addSubview:splashScreen.view]; [splashScreen displayScreen]; [self.window makeKeyAndVisible]; return YES; } 

所以,如果你在某个视图中,控制器必须使用这个方法:

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

更多说明:

UINavigationController有一个属性navigationBarHidden,允许你隐藏/显示整个导航控制器的导航栏。

让我们掠夺下一个等级:

 --UINavigationController ------UIViewController1 ------UIViewController2 ------UIViewController3 

三个UIViewController中的每一个都有导航栏,因为它们在UINavigationController中。 例如,你想隐藏第二个栏(实际上哪一个并不重要),然后写入UIViewController2:

 - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navigationController setNavigationBarHidden:YES animated:YES]; //it hides } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [self.navigationController setNavigationBarHidden:NO animated:YES]; // it shows } 

Swift 4:

 override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(true) navigationController?.setNavigationBarHidden(true, animated: true) } override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(true) navigationController?.setNavigationBarHidden(false, animated: false) } 

使用下面的一行代码来隐藏Swift3和Swift4中的导航栏

 navigationController?.setNavigationBarHidden(true, animated: true) 

显示导航栏

 navigationController?.setNavigationBarHidden(false, animated: true) 

模态地呈现开放视图,或;

  1. 不要将其添加到您的导航控制器
  2. 将其呈现导航控制器之前
  3. 一旦所有东西都加载完毕,closures打开的视图并显示导航控制器(都没有animation)。

以此线程为例: 如何在iPhone上显示更长的启animation面?

 -(void)applicationDidFinishLaunching:(UIApplication *)application { [window addSubview:splashView]; [NSThread detachNewThreadSelector:@selector(getInitialData:) toTarget:self withObject:nil]; } -(void)getInitialData:(id)obj { [NSThread sleepForTimeInterval:3.0]; // simulate waiting for server response [splashView removeFromSuperview]; [window addSubview:tabBarController.view]; }