How to hide UITabBarController programmatically? - iphone

Is it possible to hide it with animation ?

A UITabBar inherits from UIView, so you can hide it and animate it like you would with a standard UIView.
- (void) hideTheTabBarWithAnimation:(BOOL) withAnimation {
if (NO == withAnimation) {
[theTabBar setHidden:YES];
} else {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:nil];
[UIView setAnimationDuration:0.75];
[theTabBar setAlpha:0.0];
[UIView commitAnimations];
}
}

You should use this code:
self.tabBarController.tabBar.hidden=YES;

You can also hide it using the attributes inspector:
but not with an animation.

-(void)hideTabBar
{ UITabBarController * tabbarcontroller= appDelegate.tabBarVC;
if (tabbarcontroller.tabBar.isHidden)
{
return;
}
tabbarcontroller.tabBar.hidden=YES;
CGRect frm=tabbarcontroller.view.frame;
frm.size.height += tabbarcontroller.tabBar.frame.size.height;
tabbarcontroller.view.frame=frm;
}
-(void)showTabBar
{ UITabBarController * tabbarcontroller=appDelegate.tabBarVC;
if (!tabbarcontroller.tabBar.isHidden)
{
return;
}
CGRect frm=tabbarcontroller.view.frame;
frm.size.height -= tabbarcontroller.tabBar.frame.size.height;
tabbarcontroller.view.frame=frm;
tabbarcontroller.tabBar.hidden=NO;
}
here appDelegate is = (AppDelegate *) [[UIApplication sharedApplication] delegate]
tabBarVc is UITabBarController *tabBarVC defined as property in app delegate
hope this helps

Another Solution I use:
Call Methods When You Want to Hide Menu:
//Show Tab Bar
[self showTabBar:self.tabBarController];
//If You Want to Hide/Show Navigation Bar Also
[self.navigationController setNavigationBarHidden: NO animated:YES];
//Hide Tab Bar
[self hideTabBar:self.tabBarController];
//If You Want to Hide/Show Navigation Bar Also
[self.navigationController setNavigationBarHidden: YES animated:YES];
Methods:
- (void)hideTabBar:(UITabBarController *) tabbarcontroller
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width,
view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y,
view.frame.size.width, 480)];
}
}
[UIView commitAnimations];
}
- (void)showTabBar:(UITabBarController *) tabbarcontroller
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width,
view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y,
view.frame.size.width, 431)];
}
}
[UIView commitAnimations];
}

Related

iPhone Sub Tabs - Navigation

I'm in the process of designing UI for an iPhone app, and we are going to have a standard 4 tab bar across the bottom. We are considering using that same tab bar in a contextual way, so that when you tap a search result the options across the bottom will change to be contextual to the item pressed.
Does this way of doing things represent a huge usability issue, or is it Okay to-do if we are consistent about the execution?
screen1 tab navigation across bottom: A B C D:
-a search result is clicked
-new page is focused with detail view of result
screen2 tab navigation across bottom: E F G H:
It's not possible to do that on the same tabBar, you can hide the tabBar and present another tabBar with the desired items, you can hide/show the tabBar using this methods:
- (void)hideTabBar:(UITabBarController *) tabbarcontroller
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
[UIView commitAnimations];
}
- (void)showTabBar:(UITabBarController *) tabbarcontroller
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
for(UIView *view in tabbarcontroller.view.subviews)
{
NSLog(#"%#", view);
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
}
}
[UIView commitAnimations];
}
You can use these methods like this:
[self hideTabBar:self.tabBarController];
[self showTabBar:self.tabBarController];
When hiding the tabBar, initiate a new one with and add it to the view.

Iphone Hide uitabbar on first tab

There are 5 tabs in my app , first tab is a welcome tab, when user clicks the first tab it show the welcome screen, but only on first tab i want to hide the tabbar
I want to hide the tabbar on the first tab because its a welcome view. I did searching but could not hide it , i did this in my welcome controller view didload.
[self.tabBarController.tabBar setHidden:YES];
it hides but leaving the space empty.
Working on xcode 4.3.2 , storyboard, ios 5
If You Hide tabBar then how can you navigate to tab 2nd and 3rd.
I suggest to add welcomeView and after welcomeView add tabBar.
Or you can use this code
[self hideTabBar:self.tabBarController];
- (void) hideTabBar:(UITabBarController *) tabbarcontroller {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
[UIView commitAnimations];
}
[self showTabBar:self.tabBarController];
- (void) showTabBar:(UITabBarController *) tabbarcontroller {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
for(UIView *view in tabbarcontroller.view.subviews)
{
NSLog(#"%#", view);
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
}
}
[UIView commitAnimations];
}
What is the bar button name.
Give like this,
barbtnName.hidden=YES;
It will Work.
On ios 7 / 8 (xcode 6) to hide the tabbar from one view but not from the others you just need to add the following "User Defined Runtime Attributes" on the affected views (all of them):
Key Path = tabBarController.tabBar.hidden
Type = boolean
Value = true / false (depending on checkbox)
LF

Double UITabViewControllers using storyboard

Currently I have a setup with firstTabViewController hosting 5 buttons each loading a table view. When a user selects one of the table cells it opens a secondTabViewController with a set of 4 different tab buttons. I am also embedding a navigation controller.
I have set it up via storyboard and have come up with some issues. Firstly when it loads the secondTabViewController it loads it within the firstTabViewController so I have 2 sets of tab buttons on top of each other. If I change the segue to modal it loads the secondTabViewController correctly but doesn't allow me to use the navigation controller to go back.
Is there a solution to this or should I stop wasting my time with using storyboard and rather just set it up programmatically?
Screenshot: Storyboard
I use this code when I want to hide a tabbar:
I forgot where I stole it from but I'm pretty sure it was here on SO.
- (void) hideTabBar:(UITabBarController *) tabbarcontroller {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
[UIView commitAnimations];
}
- (void) showTabBar:(UITabBarController *) tabbarcontroller {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
}
}
[UIView commitAnimations];
}
Use your original strategy and then hide the first tab view controller's tab bar when you open your second tab bar view.

Cant hide UITabBar when pressing a specific tab [Tab Bar Application]-template

developers!
Im currently working on an app that uses the Tab Bar Application template. What I wanna do
is to simulate a startpage for my app that corresponds to the first tab.
So when the app start the first tab is selected and the UITabBar should not be visible.
In this "startview" there is multiple buttons that acts like the rest of the tabs, so for instance i press button #2 and the second tab view is pushed and the UITabBar is again visible.
My problem is that i have a way to hide the bar but the subview is not resizing to fullscreen.
By using:
[self.tabBarController.tabBar setHidden:YES];
I've also tried to use:
self.hidesBottomBarWhenPushed = YES;
But it seems to have no effect and I'm not sure where to add the code since I'm using
the template.
Anyone knows how to implement this by using the Tab Bar Application template?
I'm guessing it should be at the:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController: (UIViewController *)viewController
But I've tried that and that method is never being called...
Many thanks,
Robert
THis code may help you to Hide tabbarcontroller and resize the viewcontroller.
- (void) hideTabBar:(UITabBarController *) tabbarcontroller {
int height = 480;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
for(UIView *view in tabbarcontroller.view.subviews) {
if([view isKindOfClass:[UITabBar class]]) {
[view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)];
}
else {
[view setFrame:CGRectMake(view.frame.origin.x,view.frame.origin.y, 320, 436)];
}
}
[UIView commitAnimations];
}
This second method may help you to set tababr again in view
- (void) showTabBar:(UITabBarController *) tabbarcontroller {
int height = 480;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
for(UIView *view in tabbarcontroller.view.subviews) {
if([view isKindOfClass:[UITabBar class]]) {
[view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)];
}
else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, height)];
}
}
[UIView commitAnimations];
}
please understand code before implementing it in your code...

How to hide tabbar for some pages and make it visible again?

I've got an application that uses a Tab Bar Controller along with a Navigation Controller.But for some pages I want to hide both bars(Tab & navigation) after that those will be visible again...I am able to hide navigation bar & also done with making. it appear after some pages.
I am able to hide tab bar with
- (BOOL)hidesBottomBarWhenPushed{
return TRUE;
}
But problem is how do I make it Visible again after some pages?
[[self navigationController] setNavigationBarHidden:UIDeviceOrientationIsLandscape(toInterfaceOrientation) animated:YES];
then in a subclassed UITabBarController
- (void) hideTabBar:(BOOL)hide animated:(BOOL)animated {
if (tabBarHidden == hide) { return; }
if (animated) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.5];
}
for(UIView *view in self.view.subviews) {
if([view isKindOfClass:[UITabBar class]]) {
if (!hide) {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y-49, view.frame.size.width, view.frame.size.height)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y+49, view.frame.size.width, view.frame.size.height)];
}
} else {
if (!hide) {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, view.frame.size.height-49)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, view.frame.size.height+49)];
}
}
}
if (animated) { [UIView commitAnimations]; }
tabBarHidden = hide;
}