2012-05-16 231 views
23

任何人都可以告訴我如何在我的故事板中隱藏導航欄。我在下面的代碼在模擬器中運行時工作正常,但它仍然出現在我的故事板中,這真的很煩人,因爲它與我的圖像放置有關。誰能幫忙?在故事板中隱藏導航欄

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

回答

50

enter image description here

單擊具有頂欄導航到屬性欄上的控制器Xcode的右側。有一個標籤爲Top Bar的下拉列表(如上所示)將此下拉列表更改爲none。

+0

我認爲這是第一個相同的答案。 –

+0

在我輸入時添加了它 – shoughton123

+6

如果我想要每個視圖控制器,該怎麼辦? –

8

在故事板視圖,只需選擇NavigationController現場,並取消顯示導航欄(屬性檢查器)

+3

這適用於所有的孩子雖然 - 不會工作,如果你只想隱藏一個 –

8

你必須點擊實際的導航控制器,而不是視圖控制器。在視圖控制器上,導航下拉菜單不顯示,但您仍然可以通過在模擬度量標準中選擇頂欄:無。

Top Bar: None

+0

然後它不適用於單個視圖控制器。 – jowie

2

解決方案使用斯威夫特3相同的:

第1步:使用屬性檢查器中隱藏故事板導航欄: enter image description here

第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) 
}