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

hiding TabBar when rotating iPhone device to landscape(将 iPhone 设备旋转为横向时隐藏 TabBar)

本文介绍了将 iPhone 设备旋转为横向时隐藏 TabBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

So here is what i have: A UITabBarController that handles different UIViewControllers. In one of the UIViewController i am trying to switch the view being displayed when the device rotates to landscape. the important part is that the view displayed in landscape MUST take the whole screen...

我已经正确实现了方法:

I have correctly implemented the methods :

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

事实上,我确实正确地进行了轮换,并且我的观点交换了.我什至隐藏了状态栏、导航栏和标签栏,但我在屏幕底部一直有一个空白区域,这是标签栏的位置......

In fact i do have my rotation occurring correctly, and I my views swaped. i even hide status bar, nav bar and Tab bar BUT i keep having a blank space at the bottom of the screen which is the place of the TabBar...

所以我假设设置 tabBar 的 hidden 属性不足以在整个屏幕上显示视图.我认为在 TabBarController 甚至 MainWindow 中有一些事情要做,比如我现在不需要 TabBarController".但我不知道如何正确解决这个问题.

So i am assuming that setting the hidden property of the tabBar is not enough in order to have the view on the whole screen. I think there is some stuff to do within the TabBarController or even the MainWindow to say somehting like "i don't need TabBarController now". But i do not see how to get around this problem properly.

如果有人遇到过这个问题,我将不胜感激.

If anyone has been around this issue, i would appreciate some help.

谢谢你,萨米人.

推荐答案

这对我有用.


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

这篇关于将 iPhone 设备旋转为横向时隐藏 TabBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:将 iPhone 设备旋转为横向时隐藏 TabBar

基础教程推荐