-1

我正在开发通用应用程序。 当我的设备是ipad我有2种设计:肖像和风景。加载视图时检测方向

我用这个方法:-(void)orientationDidChanged:(NSNotification *)notification

它完美,当我转动我的设备。但我有一个问题,第一次加载视图时,我没有旋转设备。 出于这个原因,我把这个代码在viewDidLoad中:

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){ // 
    something. 
} 
else if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){ 
    NSLog(@"IPAD ** "); 
    if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)){ 
     NSLog(@" vertical ** "); 
    } 
    if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)){ 
     NSLog(@"Horizontal ** "); 
    } 
} 

我的问题是这样的:有时它的工作原理,有时不:(此方法:?orientationDidChanged,当开始工作只有当我转动我的设备或立即与viewDidLoad,有必要再问一次方向,当我有这种方法?感谢一些建议。

我没有问题,当我旋转我的设备,它的作品完美:D ..我的问题是当我最近运行的应用程序,我还没有打开设备

+0

我想知道为什么把我的问题标记为负面,如果你让我知道,我将不胜感激。我在学习英语,我认为我的问题很清楚,当我旋转设备时没有问题,有人告诉我我做错了什么! – user2958588

+0

我必须写好我的问题,但你需要阅读我的问题,有人删除你的答案,:(我不明白它是如何工作的! – user2958588

+0

我解决了这个问题:http://stackoverflow.com/questions/ 3382937/how-do-i-detect-an-ipads-interfacerotation-at-the-start – user2958588

回答

0

您可以使用此:

UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 
if(orientation == 0) //Default orientation 
    //UI is in Default orientation (Portrait) 
else if(orientation == UIInterfaceOrientationPortrait) 
    //UI is in Portrait orientation 
else if(orientation == UIInterfaceOrientationLandscapeLeft) 
    //UI is in Landscape-left orientation 
else if(orientation == UIInterfaceOrientationLandscapeRight) 
    //UI is in Landscape-right orientation 
+0

statusBarOrientation ??好的..我会申请..谢谢 – user2958588