在导航栏标签栏元素时,不会调用导航控制器

时间:2014-03-03 15:39:55

标签: ios uinavigationcontroller

我有一个带有2个元素的tabBarController:KeyPad,List

键盘 - 只需设置为纵向模式。在UINavigationController内部 - 我重写方法:

- (BOOL)shouldAutorotate
{
   return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
   return UIInterfaceOrientationMaskPortrait;
}

列表项从RotationNavigationController开始 - 这里我设置了所有可用的旋转。 除了一件事,一切似乎都可行:

  • 从列表项目栏控制器(在横向中)导航到键盘项目栏控制器时 - 键盘也处于横向模式。似乎没有调用2个方法(shouldAutorotate& supportedInterfaceOrientations)。怎么解决这个?

我还在viewWillApppear中添加了以下内容(在Keypad中 - 扩展了UIViewController)

if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight){
      // Landscape - WHAT TO DO HERE?
      NSLog(@"landscape");
      }

修改 * 以下是我为我的问题所做的事情: *

//set statusbar to the desired rotation position
[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeLeft animated:NO];

//present/dismiss viewcontroller in order to activate rotating.
UIViewController *mVC = [[[UIViewController alloc] init] autorelease];
[self presentModalViewController:mVC animated:NO];
[self dismissModalViewControllerAnimated:NO];

1 个答案:

答案 0 :(得分:0)

当您从一个方向标签移动到另一个方向标签时,会先调用shouldAutorotate。由于您已指定NO。它保持在以前的方向。我在setStatusBarOrientation

viewWillAppear处理了这个问题
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];

但是我必须警告你,这会改变一些事情,比如你在代码中的任何地方检查方向,你必须检查statusBarOrientation而不是view的方向/ viewController

相关问题