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.
Related
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 am making a project where the first MainPage is TabBarController(MainTabController). But then I am passing to another Viewcontroller there is one more tabbetViewControllers(secondTabbedController). And now When I pass to secondTabbedController the tabs of MainTabController are not hiding. There Should be secondTabBarController Items but there tab items of first(MainTabBarController). I guess that it is because of the navigationController and If I delete it it is fixes. But I need this NavigationController. How to fix it ?
This is ArticlesViewController that You can find in first image:
Here is the solution:
write this code in first viewcontroller
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// this will show the tabbar when come back to first viewcontroller
self.tabBarController?.tabBar.isHidden = false
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// this will hide the tabbar when moved next viewcontroller
self.tabBarController?.tabBar.isHidden = true
}
Just true this "hidesBottomBarWhenPushed" when you are pushing view controller
let objViewController: ProductDetailsViewController? = UIStoryboard.mainStoryboard().instantiateViewController(withIdentifier: "ProductDetailsViewController") as? ProductDetailsViewController
objViewController?.hidesBottomBarWhenPushed = true
navigationController?.pushViewController(objViewController ?? UIViewController(), animated: true)
And you can also set this in ViewController XIB "Attribute Inspector" by just clicking "Hide Bottom Bar on Push".
I have an app with two view controllers and an image at the top of the screen. I've hidden the navigation bar on the first (main) view controller only with no problem but using the "Back" button from the second view controller causes my image to briefly drop down as the navigation bar is hidden. I'd like to return to the first screen without the image moving at all if possible. The code I'm using to hide the navigation bar is below:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.setNavigationBarHidden(true, animated: false)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.navigationController?.setNavigationBarHidden(false, animated: true)
}
I'm using a single storyboard. Any suggestions?
In view will disappear try this
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.navigationController?.setNavigationBarHidden(false, animated: false)
}
remove animation while hiding unhiding navigation bar.
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