2009-02-14 46 views
4

我有一个与UITabBarController真正的问题。 我追求的结果如下: 1)在纵向模式下,一个简单的标签栏应用程序(带导航条)没有什么太花哨。 2)在横向模式下,我想使用我自己的UIViewController完全忽略UITabBar。UITabBarController和旋转

(我试过很多变种)我想最后我不明白为什么不“工作”的方法如下:

  • 我有一个自定义的UIViewController(调用此AA)即是假设管理“一切”。
  • 该控制器被添加到应用程序启动窗口中,并在其loadView中创建两个控制器:UITabBarController(调用此TBC)和UILandscapeController(调用此LSC)。然后我添加tabbarcontroller视图作为AA视图的子视图。
  • 现在在AA级我重写didRotate等等或willRotate等等,基本上想,这个我在两个视图之间切换是指类似:(伪代码): 从纵向去到风景:
  •  
    [TBC.view removeFromSuperView]; 
    [AA.view addSubview:LSC.view]; 
    

    并且当回到肖像反向时它。

     
    [LSC.view removeFromSuperView]; 
    [AA.view addSubview:TBC.view]; 
    

    我有问题(当然,它简单的旋转错误地创建一个真正弄乱接口)的量是一些完全无法解释。似乎tabbarcontroller视图根本不“喜欢”在标准视图中,而是希望直接附加到屏幕上。 我不知道什么是实现我的目标的最佳方法,以及为什么tabbar不喜欢成为视图的子视图,主要赞赏任何提示。

    -t

    +0

    在这里,我已经发布了我的解决方案/经验与旋转标签栏控制器:http://stackoverflow.com/a/12774037/751641 – wzbozon 2012-10-08 00:44:31

    回答

    2

    在文档中检查出UIViewController实例方法rotatingFooterView

    或者,您可以自己管理TabBar,而不是通过UITabBarController

    +1

    感谢您的提示!然而,我不明白为什么我建议的方法不起作用。 我确定必须有一种方法来创建一个我寻求的界面,它非常基本。我错过了一些简单的东西。我不认为这个问题需要创建一个完整的TabBar管理器。 还有其他建议吗? – Tzur 2009-02-14 13:34:27

    1

    你的问题来自我认为的错字。将removeFromSuperView更改为removeFromSuperview。 虽然,它仍然有问题。标签栏不能正确旋转。它向上直到消散。

    如何不删除标签栏,并使其透明。

    3

    万一你仍然需要答案,或者别人绊倒在这,我已经做了同样的事情,并得到它的工作,但有几个箍你必须跳过。为了旋转的UITabBarController认为,有四件事情你必须做的:

    1. 切换到视图
    2. 之前取出状态栏旋转视图的新框架
    3. 添加状态栏后面到视图
    4. 切换到视图。

    我有一个RootRotationController,这是否看起来像这样:

    @implementation RootRotationController 
    
    #define degreesToRadian(x) (M_PI * (x)/180.0) 
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
        if ((UIInterfaceOrientationPortrait == interfaceOrientation) || (UIInterfaceOrientationPortraitUpsideDown == interfaceOrientation)) { 
         [[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO]; 
        } 
        // Return YES for supported orientations 
        return YES; 
    } 
    
    - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration { 
        [super willAnimateRotationToInterfaceOrientation:interfaceOrientation duration:duration]; 
        if (UIInterfaceOrientationLandscapeLeft == interfaceOrientation) { 
         self.view = self.landscape.view; 
         self.view.transform = CGAffineTransformIdentity; 
         self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90)); 
         self.view.bounds = CGRectMake(0, 0, 480, 300); 
        } else if (UIInterfaceOrientationLandscapeRight == interfaceOrientation) { 
         self.view = self.landscape.view; 
         self.view.transform = CGAffineTransformIdentity; 
         self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90)); 
         self.view.bounds = CGRectMake(0, 0, 480, 300); 
        } else if (UIInterfaceOrientationPortrait == interfaceOrientation) { 
         mainInterface.view.transform = CGAffineTransformIdentity; 
         mainInterface.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0)); 
         mainInterface.view.bounds = CGRectMake(0, 0, 300, 480); 
         [[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO]; 
         self.view = mainInterface.view; 
        } else if (UIInterfaceOrientationPortraitUpsideDown == interfaceOrientation) { 
         mainInterface.view.transform = CGAffineTransformIdentity; 
         mainInterface.view.transform = CGAffineTransformMakeRotation(degreesToRadian(180)); 
         mainInterface.view.bounds = CGRectMake(0, 0, 300,480); 
         [[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO]; 
         self.view = mainInterface.view; 
        } 
    } 
    

    此外,你应该知道,shouldAutorotateToInterfaceOrientation被称为只需添加根控制器的视图到窗口后,让你必须在应用程序委托完成之后重新启用状态栏。

    相关问题