2012-04-05 104 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