34

谁能告诉我如何在我的故事板中隐藏导航栏。下面的代码在模拟器中运行时运行良好,但它仍然出现在我的故事板中,这真的让我很烦,因为它弄乱了我的图像位置。任何人都可以帮忙吗?

- (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];
}
4

6 回答 6

70

enter image description here

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.

于 2012-05-16T14:21:22.830 回答
12

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

于 2014-07-17T04:19:57.510 回答
10

在 Storyboard 视图中,只需选择 NavigationController 场景并取消选中 Shows Navigation Bar (Attributes Inspector)

于 2012-05-16T14:20:25.020 回答
7

使用Swift 3 的解决方案:

步骤 1.使用属性检查器从 Storyboard 中隐藏导航栏: 在此处输入图像描述

第 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)
}
于 2017-07-29T10:10:49.280 回答
5
Follow these step:    
    1: Go to storyboard
    2: Select navigation controller
    3: Goto Attribute inspector
    4: Under navigation controller bar visibility **Uncheck the Shows navigation Bar***

在此处输入图像描述

于 2018-06-27T07:29:24.817 回答
1

对于特定的 ViewController,将 topbar 设置为none

在此处输入图像描述

于 2020-10-25T13:39:22.390 回答