2011-10-04 47 views
1

我只有一个应用程序委托和视图控制器在我的应用程序。 该应用程序在纵向和横向模式下均可使用。 在我的视图控制器的viewWillAppear中的方法,我发现了设备usisng的方向如下代码:iPhone - 在第一个视图控制器视图中获取设备方向将出现

UIInterfaceOrientationIsPortrait([[UIDevice currentDevice] orientation]) 

当我运行的应用程序,甚至当我的设备是在肖像,其给出结果作为景观第一次。 为什么会这样。我该如何解决这个问题?

回答

5

我曾与currentDevice.orientation一吨的问题,试试这个:

UIDeviceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]) 
0
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; 


if (UIDeviceOrientationIsLandscape(deviceOrientation) 
{ 
    //LandscapeView 
} 
else 
{ 
    //PortraitView 
} 
0

从文档UIDevice

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

如果你看着'orientation'返回的实际值,你会发现它是'UIDeviceOrientationUnknown'。

相关问题