1

我的应用程序中只有一个应用程序委托和视图控制器。该应用程序适用于纵向和横向模式。在我的视图控制器的 viewWillAppear 方法中,我使用以下代码获取设备的方向:

UIInterfaceOrientationIsPortrait([[UIDevice currentDevice] orientation])

当我第一次运行应用程序时,即使我的设备是纵向的,它也会将结果显示为横向。为什么会这样。我该如何解决这个问题?

4

3 回答 3

5

我对 currentDevice.orientation 有很多问题试试这个:

UIDeviceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])
于 2011-10-04T16:46:40.167 回答
0
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;


if (UIDeviceOrientationIsLandscape(deviceOrientation)
{
   //LandscapeView
}
else
{
   //PortraitView
}
于 2011-10-04T16:35:22.597 回答
0

UIDevice的文档中:

此属性的值始终返回 0,除非已通过调用 beginGeneratingDeviceOrientationNotifications 启用了方向通知。

If you looked at the actual value being returned by 'orientation' you would see that it was 'UIDeviceOrientationUnknown'.

于 2011-10-04T16:46:55.777 回答