EDIT:我读错了你的问题。这将允许您以某些方向开始您的应用程序。刚刚意识到您正在尝试找出发射时的方向。
有一种方法可以检查状态栏方向UIApplication
:
[[UIApplication sharedApplication] statusBarOrientation];
原答案
尝试在 plist 文件中设置应用程序接受的设备方向:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
这将表明您的应用程序支持纵向(底部主页按钮)、向左横向和向右横向。
然后,在你的 UIViewControllers 中,你需要重写shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)
当应用程序应该旋转时返回 YES 的方法:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}
如果设备处于您支持的方向之一,这将告诉 UIViewController 自动旋转。如果您也想支持颠倒方向(顶部带有主页按钮的肖像),请将其添加到您的 plist 中,然后从此方法中返回 YES 即可。
让我们知道结果如何。