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?
.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)
:
where the navigationBar won't be transparent and page 1 (page with navigationBar hidden).
Example for .isHidden = true:
where the navigationBar is fully transparent and page 1 is displayed under page 2's navigationBar. Number 3 is the UIWindow.
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 you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With