為了說明白問題,先看下層級圖 .如下
屏幕快照 2017-07-12 10.25.58.png
- 我在
TwoVC
里寫了下面的方法
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: false)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.setNavigationBarHidden(false, animated: false)
}
但是如果你要是實現了全屏POP,在從
TwoVC-1
拖拽到TwoVC
界面的時候,navigationBar
會出現混亂問題于是我改為下面的方法
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: true)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.setNavigationBarHidden(false, animated: true)
}
pop的問題解決了,但是當我在
OneVC
和TwoVC
來回切換的時候發現,TwoVC會下移一下,頓時整個人就不好了!!!于是發現官方文檔解釋(隱藏或顯示導航欄。 如果動畫,它將使用UINavigationControllerHideShowBarDuration進行垂直轉換。)
Hide or show the navigation bar. If animated, it will transition vertically using UINavigationControllerHideShowBarDuration.
- 最后改為下面的方法
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: animated)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.setNavigationBarHidden(false, animated: animated)
}
完美解決問題 false -> true -> animated
- 不是很清楚為什么改為true不行,改為animated就可以了,不都是BOOL嗎?
- 如果你知道為啥,還麻煩寫下,告訴更多的人,在此謝謝~~