How to hide/show tab bar of a view with a navigation bar in iOS?
You can set the UIViewController.hidesBottomBarWhenPushed instead:
DetailViewController *detailViewController = [[DetailViewController alloc] init];
detailViewController.hidesBottomBarWhenPushed = YES;
[[self navigationController] pushViewController:detailViewController animated:YES];
[detailViewController release];
Show/Hide NavigationBar and Tab bar on tap Gesture in SwiftUI?
You need to have state in order to hide navigation bar, something like this
struct FirstView: View {
@State private var hideNavigationBar = false
var body: some View {
NavigationView {
ZStack {
PlayerView()
.edgesIgnoringSafeArea(.all)
.onTapGesture(count: 1) {
print("tapped!")
self.hideNavigationBar.toggle()
}
}
.navigationBarHidden(hideNavigationBar)
.navigationBarTitle("", displayMode: .inline)
.edgesIgnoringSafeArea([.top, .bottom])
}
}
}
hide tabbar and navigation bar
You can achieve this by having your storyboard look like this:
Then in YourMainMenuViewController
's implementation:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:animated];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
UITabBarController *tabVC = segue.destinationViewController;
if ([segue.identifier isEqualToString:@"Tab1"]) {
tabVC.selectedIndex = 0;
}
else if ([segue.identifier isEqualToString:@"Tab2"]) {
tabVC.selectedIndex = 1;
}
else if ([segue.identifier isEqualToString:@"Tab3"]) {
tabVC.selectedIndex = 2;
}
else if ([segue.identifier isEqualToString:@"Tab4"]) {
tabVC.selectedIndex = 3;
}
}
Although I advise against putting a tab bar controller inside a navigation controller like this as it's kind of confusing UI.
how to hide tab bar in the view controller that embedded in the navigation stack in swift?
Use in prepareforsegue
while pushing and set hidesBottomBarWhenPushed
to true to hide the tabbar on destination view controller.
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "InvoiceVC") {
let indexPath: IndexPath? = tableView.indexPathForSelectedRow
let destViewController = segue.destination as? InvoiceVC
destViewController?.recipeName = recipes[indexPath?.row ?? 0]
destViewController?.hidesBottomBarWhenPushed = true
}
}
How to hide tab bar in my custom navigation controller?
Seems solves my problem (code is not very good, will do some update later):
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
NSLog(@"NavigationController.pushViewController: view controller count %lu", self.viewControllers.count);
UIViewController *lastVC = nil;
if (self.viewControllers.count > 0) {
lastVC = self.viewControllers[self.viewControllers.count - 1];
}
if (lastVC != nil) {
lastVC.hidesBottomBarWhenPushed = YES;
}
[super pushViewController:viewController animated:YES];
if (self.viewControllers.count == 2) {
lastVC.hidesBottomBarWhenPushed = NO;
}
}
how to hide tab bar when push and show tab bar when back
Edit: That solved the problem.
It makes sense that the tab bar is appearing because when going clicking back from VC2 to VC3, nothing is telling VC3 to hide its Tab Bar.
I think you have 2 solutions here (but haven't tested any):
- You can try doing something like this guy did. He added the hidesBottomBarWhenPushed logic in BackButtonPressed Handler.
- In VC3, do
self.tabBarController?.tabBar.hidden = true
inViewDidLoad
orviewWillAppear
Hide TabBar and show NavigationController toolbar on button click
Eventually, after playing with the settings I managed to make it work. I'm not sure why it works now and didn't work before so I'd appreciate your comments.
Storyboard:
- Mark as checked "Hide Bottom Bar on Push" for the Custom View Controller
- Mark as checked "Show Toolbar" for the Navigation Controller
Code:
On button click hide/unhide tabBar: [self.tabBarController.tabBar setHidden:state]
This almost works. It does hide/unhide the tabBar when pressing the button but the only problem is that the tabBar is initially hidden when switching tabs. I had to do some extra effort to have it visible.
Set UITabBarControllerDelegate
to unhide tabBar when switching tabs. I did it in a custom SUSourceTabController
:
- (void)viewDidLoad
{
[super viewDidLoad];
self.delegate = self;
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController: (UIViewController *)viewController
{
[self.tabBar setHidden:NO];
}
We also need to unhide it for the first tab view in the Custom View Controller code. Using setHidden:NO
in any other place in the code didn't work.
- (void)viewDidLoad
{
[super viewDidLoad];
[self.tabBarController.tabBar setHidden:NO];
}
Related Topics
Firebase Cloud Messaging - Send Message to All Users
Passing Parameters to a Method Called by Nstimer in Swift
Can Not Save File Inside Tmp Directory
Smart-Search for Parse Usernames in Swift Not Working
Does This App Use the Advertising Identifier (IDFA)? - Admob 6.8.0
Core Data Multi Thread Application
How to Disable Floating Headers in Uitableview with Uitableviewstyleplain
Uipangesturerecognizer - Only Vertical or Horizontal
Cocoapods: Failed to Connect to Github to Update the Cocoapods/Specs Specs Repo
How to Check If a File Exists in Documents Folder
What Exactly Can Corebluetooth Applications Do Whilst in the Background
Detecting iPhone 6/6+ Screen Sizes in Point Values
Xcode 6 - How to Pick Signing Certificate/Provisioning Profile for Ad-Hoc Distribution
What Is the "Right" Way to Handle Orientation Changes in iOS 8
How to Download a File and Save It to the Documents Directory with Afnetworking