简体   繁体   English

在标签栏元素中导航时,未调用导航控制器

[英]when navigating through tab bar elements, navigation controller is not called

I have a tabBarController with 2 elements: KeyPad, List 我有一个带有2个元素的tabBarController:键盘,列表

The KeyPad- needs to be set only to portrait mode. 只需将键盘设置为纵向模式。 Inside the UINavigationController - I override the methods: 在UINavigationController内部-我重写了方法:

- (BOOL)shouldAutorotate
{
   return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
   return UIInterfaceOrientationMaskPortrait;
}

List item starts from a RotationNavigationController - here i ve set all the rotations available. 列表项从RotationNavigationController开始-在这里设置所有可用的旋转。 Everything seems to work ok except of one thing: 除了一件事,一切似乎都可以正常工作:

  • when navigating from List item Bar Controller (which is in Landscape) to KeyPad item bar controller - KeyPad is also in landscape mode. 从列表项的Bar Controller(位于横向模式)导航到KeyPad项的Bar Controller时-KeyPad也处于横向模式。 It seems that the 2 methods (shouldAutorotate & supportedInterfaceOrientations) are not called. 似乎没有调用这2个方法(shouldAutorotate和supportedInterfaceOrientations)。 How to solve this? 如何解决呢?

I;ve also added the following in viewWillApppear (inside Keypad - which extend a UIViewController) 我在viewWillApppear中也添加了以下内容(在键盘内部-扩展了UIViewController)

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

EDIT: * Here is what I did for my problem: * 编辑: * 这是我为我的问题所做的: *

//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];

When you move from one orientation tab to another, it's shouldAutorotate is called before anything else. 当您从一个方向选项卡移动到另一个方向选项卡时,应该先调用shouldAutorotate Since you have specified NO . 由于您指定了NO It stays at it's previous orientation. 它保持在以前的方向。 I worked around this by setStatusBarOrientation in the viewWillAppear : 我通过在viewWillAppearsetStatusBarOrientation解决了这个问题:

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];

But I will have to warn you, this changes some things, like if you are checking for orientation anywhere in your code, you will have to check the statusBarOrientation instead of the orientation of your view / viewController . 但是我必须警告您,这会改变某些事情,例如,如果您要检查代码中的任何位置的方向,则必须检查statusBarOrientation而不是view / viewController的方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在不同导航控制器中的选项卡栏控制器屏幕之间导航 - Navigating between tab bar controller screens in different navigation controllers 标签控制器时更改导航栏标题 - Change title of navigation bar when tab controller 如何遍历包含在标签栏控制器中的每个导航控制器 - How to iterate through each Navigation Controller cointained in a Tab Bar Controller 带标签栏控制器的导航控制器? - Navigation controller with tab bar controller? 导航控制器到选项卡栏控制器 - Navigation controller to tab bar controller 导航 Controller 和标签栏 Controller - Navigation Controller and Tab Bar Controller 具有导航控制器的标签栏控制器的导航控制器 - Navigation controller with tab bar controller of navigation controller 通过视图控制器,标签栏控制器,导航控制器和视图控制器传递数据 - Pass data through view controller, tab bar controller, navigation controller and to view controller 如果我们的标签栏带有一堆导航控制器,那么当选择一个标签时,导航控制器会弹出到底部吗? - If we have tab bar with a bunch of navigation controller, when a tab is selected, would the navigation controller pop back to bottom? 将标签栏添加到导航控制器 - Add Tab Bar to Navigation Controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM