2015-06-03 52 views
0

當我在第二個視圖控制器中並按下後退按鈕時,導航欄會殘酷地消失。我希望它從視圖控制器的屏幕上滑開。 而當我按下按鈕轉到第二個視圖控制器時,導航欄會出現在第二個視圖控制器在屏幕上。如何在導航欄的控制器之間進行更好的轉換?

  • 有沒有辦法讓導航欄更平滑的過渡?
  • 您可以爲導航欄定製過渡嗎?
var previousStatusBarHiddenState: Bool = false 

override func viewWillAppear(animated: Bool) { 
    super.viewWillAppear(animated) 

     // store navigationBar hidden state 
     if let navigationBar = navigationController?.navigationBar { 
     previousStatusBarHiddenState = navigationBar.hidden 
     navigationBar.hidden = true 
    } 

override func viewWillDisappear(animated: Bool) { 
    super.viewWillDisappear(animated) 

    // restore navigationBar hidden state 
    if let navigationBar = navigationController?.navigationBar { 
    navigationBar.hidden = previousStatusBarHiddenState 
    } 

回答

2

我發現瞭解決方案:

我用navigationController.setNavigationBarHidden(真,動畫:動畫)

override func viewWillAppear(animated: Bool) { 
    super.viewWillAppear(animated) 

     if let navigationController = navigationController { 
     previousStatusBarHiddenState = navigationController.navigationBar.hidden 
     navigationController.setNavigationBarHidden(true, animated: animated) 
    } 
} 
override func viewWillDisappear(animated: Bool) { 
    super.viewWillDisappear(animated) 

     // restore status bar 
     navigationController?.setNavigationBarHidden(previousStatusBarHiddenState, animated: animated) 
} 
相關問題