带有视图的叠加标签栏

时间:2012-09-11 13:22:44

标签: iphone ios uiviewcontroller uitabbarcontroller device-orientation

我在标签栏中有一个UIViewController。对于Tab栏中的一个VC,我允许界面在设备旋转时旋转。挑战在于,我想要隐藏标签栏并调整我的视图。

我做了什么:

1)在我的标签栏控制器中调用- (void)willAnimateRotation....并将self.tabBar.isHidden设置为true - >标签栏消失了。

2)调用- (void)willAnimateRotation....并将self.mapView.frame设置为最大高度。

但是......我仍然在屏幕底部有一个黑色条纹,与标签栏的大小完全相同。有没有办法让标签栏完全消失?

3 个答案:

答案 0 :(得分:1)

[self hideTabBar:self.tabBarController];


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

答案 1 :(得分:1)

这对我有用

- (void)viewDidLoad {
    [super viewDidLoad];    
    previousRect = self.view.frame;     
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
{
    if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {               
        [self.navigationController setNavigationBarHidden:TRUE animated:FALSE]; 
        [[UIApplication sharedApplication] setStatusBarHidden:TRUE animated:FALSE];
    }
    else
    {
        [self.navigationController setNavigationBarHidden:FALSE animated:FALSE];
        [[UIApplication sharedApplication] setStatusBarHidden:FALSE animated:FALSE];
    }
}

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    UIInterfaceOrientation toOrientation = self.interfaceOrientation;

    if ( self.tabBarController.view.subviews.count >= 2 )
    {
        UIView *transView = [self.tabBarController.view.subviews objectAtIndex:0];
        UIView *tabBar = [self.tabBarController.view.subviews objectAtIndex:1];

        if(toOrientation == UIInterfaceOrientationLandscapeLeft || toOrientation == UIInterfaceOrientationLandscapeRight) {                                     
                transView.frame = CGRectMake(0, 0, 480, 320 );
                tabBar.hidden = TRUE;
        }
        else
        {                               
                transView.frame = previousRect;         
                tabBar.hidden = FALSE;
        }
    }
}

答案 2 :(得分:1)

如果您希望在推送特定UIViewController时始终隐藏标签栏,则可以执行以下操作:

self.hidesBottomBarWhenPushed = YES;