将iPhone设备旋转到横向时隐藏TabBar

sam*_*ami 11 iphone rotation uitabbarcontroller tabbarcontroller uitabbar

所以这就是我所拥有的:一个处理不同UIViewControllers的UITabBarController.在其中一个UIViewController中,我试图在设备旋转到横向时切换显示的视图.重要的是,景观中显示的视图必须占据整个屏幕......

我已经正确实现了这些方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
Run Code Online (Sandbox Code Playgroud)

事实上,我确实正确地进行了旋转,而且我的观点也在变化.我甚至隐藏状态栏,导航栏和标签栏但我仍然在屏幕底部有一个空白区域,这是TabBar的位置...

所以我假设设置tabBar的隐藏属性是不够的,以便在整个屏幕上拥有视图.我认为在TabBarController甚至是MainWindow中都有一些事情可以说"我现在不需要TabBarController".但我不知道如何妥善解决这个问题.

如果有人围绕这个问题,我将不胜感激.

谢谢,萨米.

小智 33

这对我有用.


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

Run Code Online (Sandbox Code Playgroud)