ios 在故事板中隐藏导航栏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10620471/
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
Hide navigation bar in storyboard
提问by garethdn
Can anyone tell me how to hide the navigation bar in my storyboard. My code below is working fine when running in the simulator but it still appears in my storyboard which is really annoying me as it's messing around with the placement of my images. Can anyone help?
谁能告诉我如何在故事板中隐藏导航栏。我下面的代码在模拟器中运行时运行良好,但它仍然出现在我的故事板中,这让我很恼火,因为它弄乱了我的图像的位置。任何人都可以帮忙吗?
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
- (void) viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:animated];
}
回答by shoughton123
Click on the controller that has the top bar navigate to the properties bar on the right hand side of Xcode. There is a drop down labeled Top Bar (as shown above) change this drop down to none.
单击具有顶部栏的控制器导航到 Xcode 右侧的属性栏。有一个标记为顶部栏的下拉菜单(如上所示)将此下拉菜单更改为无。
回答by Ford Davis
You have to click the actual navigation controller, not the view controller. On the view controller the navigation drop down doesn't show up, but you can still achieve this by selecting Top Bar: none in Simulated Metrics.
您必须单击实际的导航控制器,而不是视图控制器。在视图控制器上,导航下拉菜单没有显示,但您仍然可以通过选择 Top Bar: none in Simulated Metrics 来实现这一点。
回答by LJ Wilson
In the Storyboard view, just select the NavigationController scene and UNCHECK Shows Navigation Bar (Attributes Inspector)
在 Storyboard 视图中,只需选择 NavigationController 场景并取消选中 Shows Navigation Bar (Attributes Inspector)
回答by Codetard
Solution for the same using Swift 3:
使用Swift 3的相同解决方案:
Step 1.Using attribute inspector hide Navigation Bar from Storyboard:
步骤 1.使用属性检查器从 Storyboard 中隐藏导航栏:
Step 2.Add the following code to your ViewController
:
步骤 2.将以下代码添加到您的ViewController
:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Hide the navigation bar on the this view controller
self.navigationController?.setNavigationBarHidden(true, animated: animated)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// Show the navigation bar on other view controllers
self.navigationController?.setNavigationBarHidden(false, animated: animated)
}