difference between navigationBar.isHidden and setNavigationBarHidden

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



difference between navigationBar.isHidden and setNavigationBarHidden



I have view controller which I am pushing from a view controller where navigation bar is hidden. But I want to show the navigation bar in destination view controller.



I tried with this statement it was not showing navigationBar.


self.navigationController?.navigationBar.isHidden = false



I tried this statement it is working


self.navigationController?.setNavigationBarHidden(false, animated: true)



I want to know what is difference?




3 Answers
3



Nope they are not the same,



self.navigationController?.isNavigationBarHidden


self.navigationController?.isNavigationBarHidden



is a getter property (it shows you wheather the navBar is hidden or not.) It will just return a boolean value conveying the state of the NavBar weather it is hidden or not.
(try assigning its value to bool like var isHidden = self.navigationController?.isNavigationBarHidden it will give you true of false according to state to the NavBar.)


var isHidden = self.navigationController?.isNavigationBarHidden



whereas
self.navigationController?.setNavigationBarHidden(false, animated: true)


self.navigationController?.setNavigationBarHidden(false, animated: true)



is a setter propety which gives you the provision of setting the state of the navBar.



Compiler does not throw any error on self.navigationController?.isNavigationBarHidden = false
but will not do anything as you can only know the state from here.


self.navigationController?.isNavigationBarHidden = false





isNavigationBarHidden is both a setter and a getter. setNavigationBarHidden is a setter only, and allows you to set if the bar is animated or not. isNavigationBarHidden = true and setNavigationBarHidden(true, animated: false) are treated as identical by Swift. Furthermore, the question asked about navigationBar.isHidden, which I am discovering gives you different results, depending on where it is used.
– jowie
Feb 8 at 17:50



isNavigationBarHidden


setNavigationBarHidden


isNavigationBarHidden = true


setNavigationBarHidden(true, animated: false)


navigationBar.isHidden



Effect is exactly the same, but when using second version (method) you can also define animation.



When you are doing it via property - animation is off by default.



On top of that you have another option:


self.navigationController?.isNavigationBarHidden = false



More on that topic here:
https://developer.apple.com/documentation/uikit/uinavigationcontroller/1621850-isnavigationbarhidden



If true, the navigation bar is hidden. The default value is false. 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.





if both methods does the same why this statement self.navigationController?.isNavigationBarHidden = false is not showing the navigationBar.
– santhosh
Nov 24 '17 at 10:02






@santhosh - If you were able to understand the difference in the below given answer by me, then please mark it as a right answer. Thanks.
– Ramandeep Singh Gosal
Nov 27 '17 at 6:19



.isHidden and setNavigationBarHidden() have different effects and outcomes. We won't be talking about the animated part.


.isHidden


setNavigationBarHidden()



The property of self.navigationController?.navigationBar.isHidden is an extension from UIView. The isHidden property belongs to UIView that means that navigationBar (which extends UIView) had done some overriding in isHidden causing it to have different effect and outcome compared to setNavigationBarHidden().


self.navigationController?.navigationBar.isHidden


UIView


isHidden


UIView


navigationBar


UIView


isHidden


setNavigationBarHidden()



Example for setNavigationBarHidden(true):


setNavigationBarHidden(true)



enter image description here



where the navigationBar won't be transparent and page 1 (page with navigationBar hidden).



Example for .isHidden = true:



enter image description here



where the navigationBar is fully transparent and page 1 is displayed under page 2's navigationBar. Number 3 is the UIWindow.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard