2012-04-05 106 views
3

我经历了许多不同的问题,出于某种原因,我仍然无法让我的iPad检测负载方向。无法检测负载方向 - iPad

好像要做到这一点,最好的方法是通过检测statusBarOrientation:

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    NSLog(@"View Loads"); 

    if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft 
     || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) { 
     NSLog(@"This is Landscape"); 
    } else { 
     NSLog(@"This is Portrait"); 
    } 
} 

但它总是返回“肖像”。我在我的.plist可用的所有4个方向和shouldAutorotateToInterfaceOrientation设置以及:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { 
     return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || 
       interfaceOrientation == UIInterfaceOrientationLandscapeRight || 
       interfaceOrientation == UIInterfaceOrientationPortrait);   
     } else { 
     return (interfaceOrientation == UIInterfaceOrientationPortrait); 
    } 
} 

没有人有任何其他建议吗?提前致谢!

+0

无论设备方向如何,您的应用总是以纵向显示吗? – MusiGenesis 2012-04-05 22:26:06

+0

不,我的应用可以朝着任何方向转动,除了人像颠倒。 – 2012-04-05 23:24:13

回答

4

iPad应用程序始终以纵向模式启动,无论实际的设备方向如何(如果设备处于这种状态,它们会立即旋转到横向)。如果您稍后在程序生命周期中使用相同的代码检查状态栏方向,则会看到它返回实际方向。

+0

谢谢!我发现以后要做这个动作。 – 2012-04-06 01:46:02