如何在导航栏的控制器之间实现更好的过渡?

How to have a better transition between controllers for the navigation bar?

当我在第二个视图控制器中按下后退按钮时,导航栏突然消失了。我希望它通过视图控制器从屏幕上滑开。 当我按下按钮转到第二个视图控制器时,导航栏出现在第二个视图控制器出现在屏幕上之前。

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
    }

我找到了解决方案:

我用了navigationController.setNavigationBarHidden(true, animated: animated)

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