Ios8 我们如何在iOS 8中规定应用程序方向?
在iOS 7中,我们说:Ios8 我们如何在iOS 8中规定应用程序方向?,ios8,Ios8,在iOS 7中,我们说: // ViewController1: -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; } -(BOOL)shouldAutorotate { return YES; } // ViewController2, presented by modal segue from button in ViewController
// ViewController1:
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
-(BOOL)shouldAutorotate {
return YES;
}
// ViewController2, presented by modal segue from button in ViewController1
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
-(BOOL)shouldAutorotate {
return YES;
}
结果,应用程序出现在视图控制器1的横向和视图控制器2的纵向中
该代码在iOS 7中运行良好,包括Xcode 6中的iOS 7模拟器。但它在iOS 8中不再有效。有两个问题:
- 视图控制器1的视图出现在横向视图中,但模拟器没有自动旋转(可能只是一个模拟器错误),并且(这是真正重要的部分)视图没有自动调整大小,因此对于屏幕来说太窄(右侧有一个大的黑色区域)
- 视图控制器2的视图以与视图控制器1的视图相同的方向显示(横向,而非纵向)
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
然后,如果在Info.plist支持的界面方向中首先出现横向方向,我们将连贯地启动横向方向:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortrait</string>
</array>
这并没有回答我问题的第二部分,即在显示视图控制器时如何强制旋转。正如我在中所解释的,我的感觉是在iOS 8中这将变得不可能。您的视图控制器和视图需要“适应”——您也是
编辑:在seed 4中,强制应用程序在视图控制器演示/解聘上旋转的功能似乎正在恢复 问题可能出现在您的*.plist文件中 选中此复选框,您需要将屏幕的默认/首次启动方向列为 支持的接口方向:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortrait</string>
</array>
项目0横向(右主页按钮)
项目1纵向(底部主页按钮)
在我最终检查Xcode中全局搜索的工作界面之前,我追踪了几天这个“bug”,注意到我列出了我的游戏不支持的方向(整个游戏是100%横向的)
我摆脱了横向左侧,这是GameCenter启动旋转到横向左侧的原因,如果我将设备保持在横向左侧方向
问题已解决。此情况如何:通用应用程序。在发布会上,我想要iPad的风景画,iPhone的肖像画。如何在Info.plist中进行设置?@NikitaP这很容易设置。有两个Info.plist条目描述了允许的旋转,一个用于iPad,一个用于iPhone。相应列表中的第一个将是该设备的初始方向。很好的发现。发布前的文档仍然说默认值是
NO
,我想我遇到了同样的问题,并在这里发布了我的答案:很好,Kenneth,但与我已经给出并接受的答案完全相同-我自己的答案。