隐藏和取消隐藏tabbar

时间:2011-08-03 09:30:37

标签: iphone tabbar

我有一个tabbar控制器。我想在视图中隐藏标签栏,并希望在下一个视图中取消隐藏相同的标签栏。隐藏代码适用于第一个视图,但在第二个视图中,我取消隐藏标签栏它不起作用.. < / p>

我的代码:

隐藏:

[[self navigationController] setHidesBottomBarWhenPushed:YES];

取消隐藏:

[[self navigationController] setHidesBottomBarWhenPushed:NO];

1 个答案:

答案 0 :(得分:1)

·H

 - (void) hideTabBarOfThisTabbarController:(UITabBarController *) tabbarcontroller withAnimationDuration:(int)duration;

 - (void) showTabBarOfThisTabbarController:(UITabBarController *) tabbarcontroller withAnimationDuration:(int)duration;

.m

- (void) hideTabBarOfThisTabbarController:(UITabBarController *) tabbarcontroller withAnimationDuration:(int)duration{

    [UIView transitionWithView:tabbarcontroller.tabBar duration:duration options: UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction animations:^(void) {

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

        }


    } completion:^(BOOL finished) {


        NSLog(@"tabbar hidden");

    }];


}

- (void) showTabBarOfThisTabbarController:(UITabBarController *) tabbarcontroller withAnimationDuration:(int)duration{


    [UIView transitionWithView:tabbarcontroller.tabBar duration:duration options:UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction animations:^(void) {



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


        }


    } completion:^(BOOL finished) {


        NSLog(@"tabbar shown");

    }];


    //u can call like this

    //[self hideTabBarOfThisTabbarController:self.tabBarCon withAnimationDuration:3];

    //if u want immediately hide/show the tabbar then duration should be 0.0