When I'm in the 2nd view controller and I press the back button, the navigation bar disappears brutally. I would like it to slide away from the screen with the view controller. And when I press a button to go to the 2nd view controller, the navigation bar appears before the 2nd view controller is on screen.
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
}
I found the solution :
I used 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)
}