removing the navigation title bar on the first view - ios

hey guys Im using navigation controller but what I want to do is remove the huge space made by navigation controller on the first view but retain the back button on the succeeding views. TIA

SWIFT 3.0
override func viewWillAppear(_ animated: Bool)
{
super.viewWillAppear(animated)
self.navigationController?.isNavigationBarHidden = true;
}
override func viewWillDisappear(_ animated: Bool)
{
super.viewWillDisappear(animated)
self.navigationController?.idNavigationBarHidden = false;
}

Related

Navigation bar appear on click on view

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.

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

How to get rid of the navigation bar for one screen and show for the remaining

I want to hide the navigation bar for the first view controller and show for the rest. In order to achieve this I wrote the following code :
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBarHidden = true
}
override func viewWillDisappear(animated: Bool)
{
super.viewWillDisappear(animated)
self.navigationController?.navigationBarHidden = false
}
After writing this code it works fine, i.e this view controller does not show the navigation bar and the rest show as desired. But after writing this code another problem arise which is as follows:
problem link.
According to the solution given on the above link I need to remove the code:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBarHidden = true
}
Which brings me back to problem 1
Can anybody help to get rid of both issues?
Use this instead of navigationBarHidden:
self.navigationController?.setNavigationBarHidden(true, animated: animated)
In your SecondViewController add this code:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBarHidden = false
}
On the View you want to hide navigation bar. put this code.
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBarHidden = true;
print("Navgition bar hidden")
}
On the next View, from where you want to show the navigation bar. put below code.
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBarHidden = true;
print("Navgition bar show")
}

Resources