2012-09-20 90 views
1

我不知道,如果這一個錯誤或東西,我可能做錯了,但是當我啓動我在縱向模式下應用程序而不旋轉設備和運行此代碼UIInterfaceOrientation上推出

if(UIInterfaceOrientationIsPortrait([[UIDevice currentDevice] orientation])) { 
    NSLog(@"Portrait"); 
} else { 
    NSLog(@"Landscape"); 
} 

我回到Landscape ,我旋轉設備後再次檢查它會返回正確的值,所以看起來當你第一次啓動時返回的方向是錯誤的。 這是一個已知的問題?

編輯:

即使當我運行在我的AppDelegate這段代碼它返回Landscape,甚至當我在人像模式

if(UIInterfaceOrientationIsPortrait([[UIDevice currentDevice] orientation])) { 
    NSLog(@"Portrait"); 
} else { 
    NSLog(@"Landscape"); 
} 

回答

3

這是因爲在第一次發射返回UIDeviceOrientationUnknown。它既不是肖像,也不是風景。如果您要檢測的用戶界面的方向,你應該使用

UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 
if (UIInterfaceOrientationIsLandscape(orientation)) { 
    NSLog(@"landscape"); 
}else{ 
    NSLog(@"portrait"); 
} 
+0

完美,這有助於點燃! –

0

推出在你的Info.plist>支持的接口方向拖動項目「肖像(底部主頁按鈕)「在其他項目上。

+0

它已經一切人之上,對項目0 –

-1

這是代碼爲人像模式只有

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return UIInterfaceOrientationIsPortrait(interfaceOrientation); 
} 
+0

我的應用程序支持風景和肖像模式,它的旋轉是錯的只是第一次啓動。 –

相關問題