Navigation bar is moving up to statusbar - ios

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

Related

Navigate from UIViewController to UITabBarController make double NavigationBar

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)
}

Can i fixed UINavigationBar's TopBar on the way swipe gesture

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)
}

How do I instantly hide the navigation bar on a single view controller?

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.

can't update navigationbar when popping to root view controller

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.

How can I hide navigation bar of a specific View Controller?

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

Resources