如何从一个特定的视图控制器隐藏导航栏 [英] How to hide a navigation bar from one particular view controller
问题描述
我创建了一个两个闪屏的iPhone应用程序。之后用户被带到第一个视图。我添加了一个UINavigationController。它工作得非常好。
I've created a two splash screen iPhone app. Afterwards user is taken to first view. I've added a UINavigationController. It works perfectly fine.
如何单独删除打开视图的导航栏?
How do I remove the navigation bar for the opening view alone?
MainWindow
- (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;
}
推荐答案
所以,如果你在某些视图控制器必须使用此方法:
So, if you are in some view controller have to use this method:
[self.navigationController setNavigationBarHidden:YES animated:YES];
更多说明:
More clarifications:
UINavigationController有一个属性navigationBarHidden,它允许你隐藏/显示整个导航控制器的导航栏。
UINavigationController has a property navigationBarHidden, that allows you to hide/show navigation bar for whole nav controller.
让我们在下一个层次结构中抢劫:
Let's loot at the next hierarchy:
--UINavigationController
------UIViewController1
------UIViewController2
------UIViewController3
三个UIViewController中的每一个都有导航条,因为它们是在UINavigationController中。例如,你想将bar隐藏到第二个(实际上它与哪个无关),然后写入UIViewController2:
Each of three UIViewController will have nav bar since they are in UINavigationController. For example, you want to hide bar into the second (actually it doesn't matter in which one), then write into 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
}
这篇关于如何从一个特定的视图控制器隐藏导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!