Ios 如何从一个特定视图控制器隐藏导航栏
我已经创建了一个两屏的iPhone应用程序。之后,用户被带到第一个视图。我添加了一个UINavigationController。它工作得非常好 如何仅删除打开视图的导航栏 主窗口Ios 如何从一个特定视图控制器隐藏导航栏,ios,cocoa-touch,Ios,Cocoa Touch,我已经创建了一个两屏的iPhone应用程序。之后,用户被带到第一个视图。我添加了一个UINavigationController。它工作得非常好 如何仅删除打开视图的导航栏 主窗口 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.splashScreen = [[SplashScreen alloc]
- (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;
}
以模式呈现打开视图,或
以该线程为例:
在视图控制器内尝试此方法:
// swift
self.navigationController?.setNavigationBarHidden(true, animated: true)
// objective-c
[self.navigationController setNavigationBarHidden:YES animated:YES];
更多澄清:
UINavigationController
有一个属性navigationBarHidden,允许您隐藏/显示整个导航控制器的导航栏
让我们看看下一个层次结构:
--UINavigationController
------UIViewController1
------UIViewController2
------UIViewController3
三个UIViewController中的每一个都具有相同的导航栏,因为它们位于UINavigationController中。例如,您希望隐藏UIViewController2的条形图(实际上,在哪个条形图中隐藏并不重要),然后在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
}
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)
这是为我工作的:
斯威夫特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)
}
在c#或Xamarin.IOS中,
this.NavigationController.NavigationBar.Hidden=true 最好记住它以前是否隐藏过:
private var navigationBarWasHidden = false
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Save if it was hidden initially
self.navigationBarWasHidden = self.navigationController?.isNavigationBarHidden ?? false
// Hide the Navigation Bar
self.navigationController?.setNavigationBarHidden(true, animated: animated)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// Show the Navigation Bar
self.navigationController?.setNavigationBarHidden(self.navigationBarWasHidden, animated: animated)
}
虽然这提供了一个给出适当结果的答案,但打开视图/启动屏幕不是导航控制器层次结构的一部分,因此不应该真正位于导航控制器中。我想要的是仅为第一个“打开视图”隐藏导航栏。使用上述选项将隐藏与第一个视图相关的文件的整个导航栏controller@kingston,然后再次显示它
[self.navigationController setNavigationBarHidden:NO]视图中的代码>将消失,例如:)@berylliyum:my opening page是一个表视图;这隐藏了特定表视图的导航栏,也隐藏了我的表视图中的导航视图,比如“mapview”;在我的“MapView”视图中,我能够获得导航栏。但是如果我再次导航回包含表视图的打开视图,我将再次获得导航栏。如果你能帮我解决这个问题,我将不胜感激还有-(void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)hidden animated:(BOOL)动画
方法,该方法显示/隐藏带有视图动画的导航栏。这个答案把我引向它。Thank.OP并不是指如何将闪屏显示得更长,问题根本不是关于闪屏。@berryllium也许他不是那个意思,但他说的是“一个两闪屏的iPhone应用程序”,所以他得到了关于“闪屏”的答案。问题中没有用户交互。你能详细说明你的答案吗?仅发布代码通常没有多大帮助。这很好,因为在您离开当前视图控制器后,它将显示其余视图控制器的导航栏:)。非常感谢。
private var navigationBarWasHidden = false
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Save if it was hidden initially
self.navigationBarWasHidden = self.navigationController?.isNavigationBarHidden ?? false
// Hide the Navigation Bar
self.navigationController?.setNavigationBarHidden(true, animated: animated)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// Show the Navigation Bar
self.navigationController?.setNavigationBarHidden(self.navigationBarWasHidden, animated: animated)
}