iPhone hide Navigation Bar only on first page
The nicest solution I have found is to do the following in the first view controller.
Objective-C
- (void)viewWillAppear:(BOOL)animated {
[self.navigationController setNavigationBarHidden:YES animated:animated];
[super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
[self.navigationController setNavigationBarHidden:NO animated:animated];
[super viewWillDisappear:animated];
}
Swift
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)
}
This will cause the navigation bar to animate in from the left (together with the next view) when you push the next UIViewController
on the stack, and animate away to the left (together with the old view), when you press the back button on the UINavigationBar
.
Please note also that these are not delegate methods, you are overriding UIViewController
's implementation of these methods, and according to the documentation you must call the super's implementation somewhere in your implementation.
iOS - Cannot hide navigation bar on first page
First of all,I will go to solve your problem.And then I will state about UINavigationController.
So you use SB create some viewControllers in Main.storyboard
.These viewControllers must should inherit UITabBarController,UINavigationController or ViewController.
I see your screenshoot that is right,otherwise your screenshoot is unclearly.
If you want to edit or layout view,you need to create ViewController and match this ViewController with in Main.storyBoard
.I will test these operation.you will can this.
And then these ViewControllers inherit match ViewController.
HomeTabBarViewController
FirstViewController
SecondViewController
As mentioned above,that is very clearly. if you want to hiddn navigationBar in this first page,you must handwritten code in FirstViewController
.Also you operate in viewWillAppear:
self.navigationController.navigationBar.hidden = YES;
that's all.
If you handwritten code hidden navigationBar in HomeTabBarViewController inherit UITabBarController,because navigationController is next ViewController that is not work in hidden code.
So UINavigationController have auto create navigation bar.You want to not show this navigation bar to use hidden navigation bar in viewWillAppear
.And also you want to hidden this page and next page show,you can this viewWillAppear
to hidden,viewWillDisAppear
to show.
I wish can help you for resolve problem.
iOS - Hide navigation bar only on one view?
Add this:
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:animated];
}
iOS: Hide the navigation bar for only one viewcontroller which is root of the UINavigationController?
I got the another way to hide/show navigationbar from one of my friend.
- Set a delegate for the NavigationController:
navigationController.delegate = self
- Hide/Show navigationbar for each ViewController all in one place
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
let hide = (viewController is YourVC)
navigationController.setNavigationBarHidden(hide, animated: animated)
}
Navigation bar show/hide
This isn't something that can fit into a few lines of code, but this is one approach that might work for you.
To hide the navigation bar:
[[self navigationController] setNavigationBarHidden:YES animated:YES];
To show it:
[[self navigationController] setNavigationBarHidden:NO animated:YES];
Documentation for this method is available here.
To listen for a "double click" or double-tap, subclass UIView
and make an instance of that subclass your view controller's view
property.
In the view subclass, override its -touchesEnded:withEvent:
method and count how many touches you get in a duration of time, by measuring the time between two consecutive taps, perhaps with CACurrentMediaTime()
. Or test the result from [touch tapCount]
.
If you get two taps, your subclassed view issues an NSNotification
that your view controller has registered to listen for.
When your view controller hears the notification, it fires a selector that either hides or shows the navigation bar using the aforementioned code, depending on the navigation bar's current visible state, accessed through reading the navigation bar's isHidden
property.
EDIT
The part of my answer for handling tap events is probably useful back before iOS 3.1. The UIGestureRecognizer
class is probably a better approach for handling double-taps, these days.
EDIT 2
The Swift way to hide the navigation bar is:
navigationController?.setNavigationBarHidden(true, animated: true)
To show it:
navigationController?.setNavigationBarHidden(false, animated: true)
How to hide a navigation bar from first ViewController in Swift?
If you know that all other views should have the bar visible, you could use viewWillDisappear
to set it to visible again.
In Swift:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: animated)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.setNavigationBarHidden(false, animated: animated)
}
Related Topics
Measuring Cellular Signal Strength
Implicitly Unwrapped Optional Assign in Xcode 8
Impact of Xcode Build Options "Enable Bitcode" Yes/No
How to Show "Done" Button on iOS Number Pad Keyboard
Uiwebview Open Links in Safari
Openurl Not Work in Action Extension
Handling Applicationdidbecomeactive - "How Can a View Controller Respond to the App Becoming Active"
What Is Silent Push Notification? When Does the Device Receive It
Uicolor Not Working With Rgba Values
How to Create a Custom iOS View Class and Instantiate Multiple Copies of It (In Ib)
How to Change the Title of the "Back" Button on a Navigation Bar
How to Increment the Filename If File Already Exists
Wait For Firebase to Load Before Returning from a Function
Using Auto Layout in Uitableview For Dynamic Cell Layouts & Variable Row Heights