【发布时间】:2012-08-21 18:04:39
【问题描述】:
我有一个以纵向模式呈现的 UITabBarController。在其中一个选项卡上,我有一个以模态方式显示 UIViewController 的按钮(一个简单的故事板 segue 执行操作)。
我希望这个模态视图以横向模式显示,但我无法让它自动转动。
我在模态视图控制器中有这个
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
我已将 LandscapeLeft 添加到 .plist 支持的方向(尽管这也允许我不希望旋转 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 已弃用,因此我需要阅读新方法。
【问题讨论】:
-
从我以前的经验来看,没有办法强制 viewController 出现在特定的方向。您可以选择是否允许更改方向,但不能强制更改。这对我来说是一个无赖...
-
真的有点傻!我有一个只适合横向的图表。所以你说苹果想让我把它搞砸了,直到用户转动他的设备。这听起来不对,虽然我还没有找到解决方案,所以你可能是对的。
标签: ios xcode cocoa-touch modalviewcontroller uiinterfaceorientation