I have a UITabBarController
where the default view controller is a UINavigationController
. I want to be able to hide the UITabBar of the UITabBarController when I push a certain view in the UINavigationController
.
I've tried adding:
delegate.tabBarController.hidesBottomBarWhenPushed = YES;
in my UINavigationController
before I push the view, but that doesn't seem to do the trick.
Any tips on what I should be doing or if it's even possible? Thanks in advance!
Source: Tips4all
This is better:
ReplyDeletethe_ui_view_controller_to_push_in.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:the_ui_view_controller_to_push_in animated:YES];
You have to set hidesBottomBarWhenPushed = YES on the controller you are going to push into the view...
The hidesBottomBarWhenPushed doesn't apply to tab bars. It applies to button bars that you have configured on the UIViewController inside the UINavigationController.
ReplyDeleteI'm guessing your app has the UINavigationController inside the UITabBarController (this is the standard arrangement). This means that pushing a new navigation view can't affect the UITabBar (since the tab bar is outside the control of the UINavigationController).
There are two ways around this:
Put the tab bar inside the navigation control (push the UITabBarController into the navigation controller). The tab bar will slide left/right as any normal UIViewController.
Use a modal view controller instead (this will replace the whole screen but animates differently to standard navigation views). The advantage with this is it presents a clear, distinct interface -- good for special behavior. Read documentation for presentModalViewController:animated: (or interweb search it) for details on how this is done.
edit: If you want tabs/bars within a view, perhaps you should consider using UISegmentedControl (for tab-like control) or UIToolbar (for bars).
It turns out that if you set the view hidesBottomBarWhenPushed:YES it hides the bar when the view appears (duh on my part). I was assigning it to the UITabBarController, which doesn't make too much sense when you think about it.
ReplyDelete[self.view hidesBottomBarWhenPushed:YES];
[super pushViewController:viewController animated:animated];
I'll let here my solution for this:
ReplyDelete#define FRAME_HIDDEN CGRectMake(0, 0, 768, 1073) //1073 = 1024 (screen) + 49 (UITabBar)
#define FRAME_APPEAR CGRectMake(0, 0, 768,1024)
-(void) setHidden: (BOOL) hidden{
CGRect frame = (hidden)? FRAME_HIDDEN : FRAME_APPEAR;
[self.tabBarController.view setFrame:frame];
[self.tabBarController.tabBar setHidden:hidden];
}
Calls the 'setHidden' method where you need it! I using this and the 'Singleton Pattern', then my subviews can hide the UITabBar in his Superview
Here's how you get this to work:
ReplyDeleteIn the Application Delegate you create the UITabBarController. Then you create a UINavigationController with its root controller as the view controller you want in the particular tab. Then insert the UINavigationController into the "viewControllers" array of the UITabBarController. like so:
ViewControllerForTab1 *tab1Controller = [[ViewControllerForTab1 alloc] initWithNibName:@"ViewControllerForTab1"];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:tab1Controller];
[tab1Controller release];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects: navController, nil];
[navController release];
[self.window addSubView:tabBarController.view];
This way you can set the "hidesBottomBarWhenPushed" property to "YES" in any view controller inside that UINavigationController and it will hide the UITabBar.
Hope that helps!
I've figure out how to get this solved, I was running into the same issue, but Apple also tells us how to do it in the sample called: "The Elements" (http://developer.apple.com/library/ios/#samplecode/TheElements/Introduction/Intro.html)
ReplyDeleteSee function below on how to do it, add this to the init function of the view you want to push in!
-(id) init {
if(self = [super init]) {
self.hidesBottomBarWhenPushed = YES;
}
return self;
}
It will automatically hide the tabbar like the photo app does on your iphone. And when you navigate back the parent view will just show the tabbar again.
Good luck