问题描述:

In one of the view controller UITabBar has been set hidden and in the same place one CustomView with UITextField is added, But the entire CustomView is not taking any action.

If custom view is placed above the UITabBar it works fine. But I want to hide the Tab Bar in and place CustomView in the same frame.

I am using the below code to hide the Tab Bar

[self.tabBarController.tabBar setHidden:YES];

TaB Bar is added like this

[self.window addSubview:self.tabBarController.view];

网友答案:

Hiding the UITabBar does not still allow view below it to work. You will have to manually move the UITabBar when you want to hide and manually bring it back when you want to unhide if you want this functionality. The following code would work:

- (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];   
}

If you want to move a particular tab bar button instead of the complete controller, you may have to do a little tweaking in the code.

Another option is to use hideBottomBarWhenPushed option like this self.hidesBottomBarWhenPushed = true;

网友答案:

There is a property in UIViewController exactly for this reason - hidesBottomBarWhenPushed;

If you use storyboard then you can set this in view controller's attributes inspector in the storyboard - this is the best solution IMHO.
Like this:

If you don't use storyboard then you can set this property to YES in in viewDidLoad or in 'init' of the view controller that should hide the tab bar.
Something like this:

- (void)viewDidLoad {
    [super viewDidLoad];

    self.hidesBottomBarWhenPushed = YES;
}
网友答案:

I use the following code resize views when hiding/unhiding tabBar :

- (void)hideTabBar{


    for (UIView *view in self.tabBarController.view.subviews) {

        if ([view isKindOfClass:[UITabBar class]]) {

            view.frame = CGRectMake(view.frame.origin.x,
                                    [UIScreen mainScreen].bounds.size.height,
                                    view.frame.size.width,
                                    view.frame.size.height);
        } else {

            view.frame = CGRectMake(view.frame.origin.x,
                                    view.frame.origin.y,
                                    view.frame.size.width,
                                    [UIScreen mainScreen].bounds.size.height);
        }
    }
}

- (void) showTabBar {    


    for (UIView *view in self.tabBarController.view.subviews) {


        if ([view isKindOfClass:[UITabBar class]]) {

            view.frame = CGRectMake(view.frame.origin.x,
                                    [UIScreen mainScreen].bounds.size.height - 49,
                                    view.frame.size.width,
                                    view.frame.size.height);

        } else {

            view.frame = CGRectMake(view.frame.origin.x,
                                    view.frame.origin.y,
                                    view.frame.size.width,
                                    [UIScreen mainScreen].bounds.size.height - 49);
        }
    }
}

Where 49 is the height of the tabBar.

相关阅读:
Top