Search code examples
iphoneiosios4uitabbarcontrolleruitabbar

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


Solution

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