我创建了一个两个闪屏的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;
}
Run Code Online (Sandbox Code Playgroud)
ber*_*ium 145
所以,如果你在某些视图中,控制器必须使用这种方法:
// swift
self.navigationController?.setNavigationBarHidden(true, animated: true)
// objective-c
[self.navigationController setNavigationBarHidden:YES animated:YES];
Run Code Online (Sandbox Code Playgroud)
更多说明:
UINavigationController有一个属性navigationBarHidden,它允许您隐藏/显示整个导航控制器的导航栏.
让我们在下一个等级中掠夺:
--UINavigationController
------UIViewController1
------UIViewController2
------UIViewController3
Run Code Online (Sandbox Code Playgroud)
三个UIViewController中的每一个都有导航栏,因为它们位于UINavigationController中.例如,你想将bar隐藏到第二个(实际上它与哪一个无关),然后写入UIViewController2:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES]; //it hides the bar
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES]; // it shows the bar back
}
Run Code Online (Sandbox Code Playgroud)
小智 17
斯威夫特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)
}
Run Code Online (Sandbox Code Playgroud)
小智 6
这对我有用:
斯威夫特 4
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: false)
}
//reappears navigation bar on next page
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.setNavigationBarHidden(false, animated: true)
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
60888 次 |
最近记录: |