Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 557
AppleBee Avatar asked Nov 24 '17 09:11

AppleBee


2 Answers

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

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().

Example for 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.

like image 113
Brandon WongKS Avatar answered Sep 25 '22 15:09

Brandon WongKS


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.

like image 40
Grzegorz Krukowski Avatar answered Sep 22 '22 15:09

Grzegorz Krukowski