[英]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:
除了一件事,一切似乎都可以正常工作:
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
: 我通过在
viewWillAppear
的setStatusBarOrientation
解决了这个问题:
[[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.