UITabBar不会隐藏

时间:2011-04-18 17:26:04

标签: iphone objective-c uinavigationcontroller uitabbarcontroller uitabbar

我在UITabBarController中有一个UINavigationController,我似乎无法通过推送viewController的tabBar来隐藏它。

我使用以下代码隐藏它:

在被推之前:

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

viewWillAppear中:

self.tabBarController.tabBar.hidden = YES;

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

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

但上述工作都没有。

如果你能告诉我如何解决这个问题,那就太好了。

3 个答案:

答案 0 :(得分:4)

在推送新视图控制器之前设置此项:

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

[编辑:评论重新使用]

刚刚注意到你说你试过这个。不确定在推送VC或配置VC的情况下你还在做什么,但这确实可行。这就是我在我的应用程序中执行此操作的方式。

答案 1 :(得分:2)

- (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 :(得分:0)

我遇到了与

相同的问题
myVC.hidesBottomBarWhenPushed = YES;

它不会删除后续视图中的标签栏。可能是它被弃用了。你不应该使用setHidesBottomBarWhenPushed:命令来解决这个问题。尝试使用以下视图:

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