ios UINavigationController 没有导航栏?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5765946/
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
UINavigationController without navigation bar?
提问by DOOManiac
I have a universal app, and on the iPad version I'm using UISplitViewController
to create an interface similar to the Mail app.
我有一个通用的应用程序,在 iPad 版本上我用它UISplitViewController
来创建一个类似于邮件应用程序的界面。
I was having trouble pushing new Detail views, so I decided to use a UINavigationController
so I could just push and pop views as needed. However, I do not want to use the navigation view or a toolbar. But no matter what I do, I can't hide the navigation bar.
我在推送新的 Detail 视图时遇到了麻烦,所以我决定使用 aUINavigationController
以便我可以根据需要推送和弹出视图。但是,我不想使用导航视图或工具栏。但是无论我做什么,我都无法隐藏导航栏。
I've tried unchecking "Shows Navigation Bar" in IB, and I've also tried setting:
我试过在 IB 中取消选中“显示导航栏”,我也试过设置:
[self.navigationController setNavigationBarHidden:YES];
in the viewDidLoad
/viewDidAppear
/viewWillAppear
. I've also tried it in each of the views that will be pushed. Nothing works.
在viewDidLoad
/ viewDidAppear
/ viewWillAppear
。我也在每个将被推送的视图中尝试过。什么都行不通。
Is there something I'm missing here? Is it possible to have a UINavigationController
without a toolbar or navigation bar?
有什么我在这里想念的吗?是否可以UINavigationController
没有工具栏或导航栏?
回答by Ashwin
You should be able to do the following:
您应该能够执行以下操作:
self.navigationController.navigationBar.isHidden = true //Swift 5
where self.navigationController is (obviously) an instance of UINavigationController. Seems to work for me, but I only briefly tested it before posting this.
其中 self.navigationController 是(显然)UINavigationController 的一个实例。似乎对我有用,但在发布之前我只是对其进行了简短的测试。
回答by HalR
If you want no navigation bar, and you want the content to be adjusted up to where the navigation bar normally would be, you should use
如果您不想要导航栏,并且希望将内容调整到导航栏通常所在的位置,则应使用
self.navigationController.navigationBarHidden = YES;
This gives you a result like this:
这会给你一个这样的结果:
Whereas self.navigationController.navigationBar.hidden = YES;
gives you a space where the navigationBar should be. Like this:
而self.navigationController.navigationBar.hidden = YES;
给你一个导航栏应该在的空间。像这样:
回答by Avner
In Xcode 4.3.2:
在 Xcode 4.3.2 中:
- Select the navigation controller in the storyboard
- Select the Attributes Inspector in the (right) Utilities panel
Under the Navigation Controller category you have two check boxes:
[] Shows Navigation Bar
[] Shows Toolbar
- 在故事板中选择导航控制器
- 在(右侧)Utilities 面板中选择 Attributes Inspector
在导航控制器类别下,您有两个复选框:
[] 显示导航栏
[]显示工具栏
Worked for me...
为我工作...
回答by user1296082
Swift 4
斯威夫特 4
I hide it in viewWillAppear
我将它隐藏在 viewWillAppear 中
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.isNavigationBarHidden = true;
}
Then you can put it back when you push a segue (if you want to have the back button on the next view)
然后你可以在你推动 segue 时把它放回去(如果你想在下一个视图上有后退按钮)
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
{
self.navigationController?.isNavigationBarHidden = false;
}
回答by Mobile Dan
Swift 3 Programmatically
Swift 3 以编程方式
self.navigationController.isNavigationBarHidden = true
or
或者
self.navigationController.navigationBar.isHidden = true
Note: I didn't see a difference between these two approaches testing on iOS 10.
注意:我没有看到这两种在 iOS 10 上进行测试的方法之间的区别。
回答by Cbas
All these answers still leave a space at the top for the status bar - add this line to remove that as well:
所有这些答案仍然在状态栏的顶部留出一个空间 - 添加此行以将其删除:
navController.navigationBar.isHidden = true
navController.accessibilityFrame = CGRect.zero