为了说明白问题,先看下层级图 .如下
- 我在
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吗?
- 如果你知道为啥,还麻烦写下,告诉更多的人,在此谢谢~~