今天做项目,从无导航栏页面跳转包含导航条页面时,使用的是self.navigationController.navigationBar.hidden = YES; 可是随着左滑pop回上一级界面时,发现导航条消失不见。
首先想到是不是在viewWillAppear中添加一遍导航条不隐藏,结果不起作用。
随后就尝试了self.navigationController.navigationBarHidden = YES;没想到立马就解决了这个问题。所以想看看这两个隐藏的区别。
官方解释:
navigationBarHidden
A Boolean value that indicates whether the navigation bar is hidden.
Discussion
If YES, the navigation bar is hidden. The default value is NO. Setting this property changes the visibility of the navigation bar without animating the changes. If you want to animate the change,
use the setNavigationBarHidden:animated:method instead.
navigationBar
The navigation bar managed by the navigation controller.
Discussion
It is permissible to customize the appearance of the navigation bar using the methods and properties of the UINavigationBar class but you must never change its frame, bounds, or alpha values or modify its view hierarchy directly.
To show or hide the navigation bar, you should always do so through the navigation controller by changing its navigationBarHidden property or calling the setNavigationBarHidden:animated: method.
同样都是会调用setNavigationBarHidden:animated:method 但是却有着细微的差别。
在网上查了一下,说的都是navigationBarHidden会隐藏整个navigationController,而navigationBar.hidden作用于nabigationbar;
具体情况在官方我还没有找到,但是使用navigationBarHidden能够解决pop手势左滑导致导航条空白的问题。
利用pop左滑手势回去时,在viewWillDisAppear中打断点,lldb查看情况
(lldb) po self.navigationController.navigationBarHidden
false
(lldb) po self.navigationController.navigationBar.hidden
false
可以看出这个时候两个状态是一样的。
当再次点击进入下一级页面时,就可以看到,两者的差别
(lldb) po self.navigationController.navigationBarHidden
<nil>
(lldb) po self.navigationController.navigationBar.hidden
false
网友评论