我有一个在竖屏模式下显示的UITabBarController。在其中一个选项卡上,我有一个按钮,可以以模态形式显示一个UIViewController(使用简单的故事板segue执行操作)。
我希望此模态视图在横向模式下显示,但我无法使其自动旋转。
在模态视图控制器中,我有以下内容:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
我已经在 .plist 支持的方向中添加了 landscapeLeft(尽管这也允许 TabBar 旋转,但我不希望)
我还将此添加到模态视图的 ViewDidLoad 中
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;
但是我无法让它自己旋转。
谢谢
编辑 ----
似乎 shouldAutoRotate 没有被调用!
另外,我正在尝试检测方向,但以下代码始终显示2,无论方向如何!
if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortrait) {
NSLog(@"1");
self.hostView.frame = CGRectMake(0, 60, 200, 255);
} else {
NSLog(@"2");
self.hostView.frame = CGRectMake(0, 45, 480, 255);
}
编辑2 ---
抱歉,我应该提到我正在使用iOS 6。在iOS 5上,显示屏会自动旋转。 shouldAutorotateToInterfaceOrientation已经被弃用,因此我需要研究新的方法。