编辑: 我误读了你的问题。这将允许您在特定方向中启动应用程序。刚意识到您正在尝试在启动时确定方向。
有一种方法可以在UIApplication
上检查状态栏方向:
[[UIApplication sharedApplication] statusBarOrientation];
尝试在plist文件中设置应用程序接受的设备方向。
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
这将表明您的应用程序支持纵向(home按钮在底部),左横向和右横向。
然后,在您的UIViewControllers中,您需要重写shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)
方法,以便在应用程序需要旋转时返回YES:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}
这会告诉UIViewController,在设备处于支持的方向之一时自动旋转。如果您还想支持倒置方向(Home键在上方的肖像模式),请将其添加到您的属性列表中,并只需从此方法返回YES即可。
让我们知道它的工作原理。