Skip to main content

Hiding UITabBar when pushing a UIView



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

Comments

  1. This is better:

    the_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...

    ReplyDelete
  2. The hidesBottomBarWhenPushed doesn't apply to tab bars. It applies to button bars that you have configured on the UIViewController inside the UINavigationController.

    I'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).

    ReplyDelete
  3. 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.

    [self.view hidesBottomBarWhenPushed:YES];
    [super pushViewController:viewController animated:animated];

    ReplyDelete
  4. I'll let here my solution for this:

    #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

    ReplyDelete
  5. Here's how you get this to work:

    In 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!

    ReplyDelete
  6. 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)

    See 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

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex