I want to navigate from the login screen to UITabBarController.
I use this Line to navigate --> navigationController?.pushViewController(tabBarVC, animated: true)
When navigate show me two NavigationBar.
I want to solve this problem.
Make a subclass of UITabBarController for your tabBarVC,
Add these lines:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: true)
}
Related
I attach the video of my issue. When i click on anywhere in viewcontroller navigation bar is appear
override func viewWillAppear(_ animated: Bool) {
self.navigationController?.setNavigationBarHidden(true, animated: true)
self.navigationController?.isNavigationBarHidden = true
self.navigationController?.hidesBarsOnTap = true
}
The above code added on viewwillappear its working on initially but when I click anywhere on screen navigationbar is appear.
Finally this solutions work for me
self.navigationController?.navigationBar.transform = CGAffineTransform(translationX: 0, y: -200)
Try Below code into ViewController you want to hide NavigationBar
DispatchQueue.main.async {
self.navigationController?.setNavigationBarHidden(true, animated: false)
self.view.isUserInteractionEnabled = true
//Below code conflicts with the hidden `NavigationBar` and make it visible on tap so set it false as below
self.navigationController?.hidesBarsOnTap = false
}
And ADD Below code in Other ViewController you want to show Navigationbar (Not in every other ViewController , just in ViewController you push or pop from thisViewController)
self.navigationController?.setNavigationBarHidden(false, animated: true)
Try with global queue
DispatchQueue.global().async {
navigationController?.setNavigationBarHidden(true, animated: animated)
}
or simple add this code in viewDidAppear
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: animated)
}
if this two won't work then check your view tap event may be there is some code added for navigation
Check out your main UINavigationController storyboard properties in storyboard and uncheck the "Hide bars when vertically compact", "Hide bars on tap". this causes the navigation bar to appear when click on view.
if you are creating UINavigationController programmatically then use following code.
UINavigationController().hidesBarsWhenVerticallyCompact = false
UINavigationController().hidesBarsOnTap = false
TRY TO BELOW
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.isNavigationBarHidden = true
}
override func viewWillDisappear(_: Bool) {
super.viewWillDisappear(true)
navigationItem.title = ""
}
I had a same problem too.Storyboard I deleted and recreated the viewController and it was fixed. For this reason I think the problem is related to the viewController not related to the NavigationController. I suggest you delete and recreate the viewController.
I want UINavigationBar's Topbar on the way swipe gesture.
My storyboard is like this:
LoginViewController(UINavigationController) =>(pushViewController) RegisterViewController
I tried some methods, The most similar answer is
LoginViewController's Navigation bar set to hidden. setNavigationBarHidden(true, animated: true)
RegisterViewController's Navigation bar set to show. self.navigationController?.setNavigationBarHidden(false, animated: true)
But, This method is must have LoginViewController's navigation bar set to hidden.
Is there another good way?
Result) https://puu.sh/Ei30r/14dc30d883.jpg
I want) https://puu.sh/Ei32K/437b731c80.jpg
Replace img tag with link because i have not at least 10 reputation.
Sorry,
I've tried this and it worked. You can give it a try.
on LoginViewController's
override func viewWillAppear(_ animated: Bool) {
navigationController?.setNavigationBarHidden(true, animated: true)
}
on RegisterViewController's
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(false, animated: true)
}
I have a UITabBar. In one tab is a UINavigationController. Let's say the 2nd or 3rd UIViewController in the stack has this:
class ChildVC: UIViewController {
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)
}
}
If you click the current tab it will popToRootViewController() on the navigation controller. The problem is, in viewWillDisappear(:) of my current tab the navigationController is nil. So the navigationBar remains hidden.
What's the proper way to handle this? Should I just set the navigation bar to visible in the root view controller's viewDidAppear? That seems hacky.
If anybody else sees this, I don't know why the reference to self.navigationController gets set to nil before viewWillDisappear when you popToRootViewController() but a workaround I found was just to store your own reference to it.
class ChildVC: UIViewController {
private weak var navCtrl: UINavigationController?
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navCtrl = navigationController
navCtrl?.setNavigationBarHidden(true, animated: false)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navCtrl?.setNavigationBarHidden(false, animated: false)
}
}
You should override the viewWillAppear in the rootViewController and setNavigationBarHidden from there. navigationController is nil at viewDidDisappear because it has already been popped off the navigation stack.
I have a viewController. Which does not have navigationBar. I am pushing another viewController that has navigationBar. Which is going up
I am using following code to show the navigationBar
self.navigationController?.setNavigationBarHidden(false, animated: false)
I believe you trying to hide navigationBar in firstVC and show it in secondVC.
Try following method into your firstVC and make sure you embedded your firstVC with navigationController.
Your storyBoard flow layout should be look like below...
Implement below method in firstVC.
override func viewWillAppear(_ animated: Bool) {
self.navigationController?.setNavigationBarHidden(true, animated: true)
}
override func viewWillDisappear(_ animated: Bool) {
self.navigationController?.setNavigationBarHidden(false, animated: true)
}
Output:Updated
What I am trying is to set a ViewController(root) with a NavigationController that will connect with three ViewController.
Two of the linked ViewController have to have a NavigationBar on the top of each screen. The other one do not have to have the Navigation bar. Further, the root View Controller do not have to have a Navigation bar.
I hide the NavigationBar on the root View Controller as follows:
override func viewWillAppear(_ animated: Bool) {
self.navigationController?.setNavigationBarHidden(true, animated: animated)
super.viewWillAppear(animated)
}
override func viewWillDisappear(_ animated: Bool) {
self.navigationController?.setNavigationBarHidden(false, animated: animated)
super.viewWillDisappear(animated)
}
but I am not able to hide the Navigation bar on the linked View Controller that does not have to have the Navigation bar.
I have also tried on the viewDidLoad function of the View Controller in which I want to hide the Navigation bar using:
self.navigationController?.setNavigationBarHidden(false, animated: true)
but the Navigation bar is still being shown.
How can I hide the Navigation bar on a specific View Controller?
Thanks in advance!
You can Try like this:-
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.navigationController!.navigationBarHidden = true
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
self.navigationController!.navigationBarHidden = false
}
You are making mistake, in question you have set falsein viewDidLoad to hide navigationBar, you need to set true instead of false, also try on viewDidAppear.
self.navigationController?.setNavigationBarHidden(true, animated: true)
Use below code in viewDidAppear method
self.navigationController?.setNavigationBarHidden(true, animated: true)
Try this code in viewDidAppear :-
self.navigationController?.navigationBarHidden = true