UITabBar wont hide

亡梦爱人 提交于 2019-12-10 12:07:30

问题


I have a UINavigationController in a UITabBarController, and I can't seem to get a pushed viewController's tabBar to hide.

I am using the following code to hide it:

Before it gets pushed:

tpsv.hidesBottomBarWhenPushed = YES; tpsv.tabBarController.hidesBottomBarWhenPushed = YES;

viewWillAppear:

self.tabBarController.tabBar.hidden = YES;

AppDelegate *del = (AppDelegate *)[[UIApplication sharedApplication] delegate];

[[[del tabController] tabBar]setHidden:YES];

But none of the above work.

If you could tell me how to fix this, that would be great.


回答1:


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



回答2:


You set this before you push the new view controller:

MyViewController *myVC = [[[MyViewController alloc] init] autorelease];
myVC.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:myVC animated:YES];

[EDIT: comment re usage]

Just noticed you say you tried this. Not sure what else you're doing in the context of pushing your VC or configuring it but this does work fine. It's how I do this exact thing in my apps.




回答3:


I've faced the same problem with

myVC.hidesBottomBarWhenPushed = YES;

It does'nt remove the tab bar in subsequent views. May be it's deprecated. You should'nt face this problem with the setHidesBottomBarWhenPushed: command. Try using the following for views:

MyViewController *myVC = [[[MyViewController alloc] init] autorelease];
[myVC setHidesBottomBarWhenPushed:YES];
[self.navigationController pushViewController:myVC animated:YES];


来源:https://stackoverflow.com/questions/5706536/uitabbar-wont-hide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!