2011-09-28 68 views
2

檢測設備顛倒的正確值是什麼?顛倒檢測設備

我有以下幾點,它開始檢測用戶標題背面的設備。

我使用下列值

float xx = -[acceleration x]; 
    float yy = [acceleration y]; 
    float angle = atan2(yy, xx); 

    if(angle >= 0.75 && angle <= 2.25) 
    { 
     NSLog(@"Upside down"); 
    } 
+0

不要試圖在這裏推倒重來。這在UIDevice API中有記錄。 –

回答

7

開始利用監聽定位事件:

UIDevice *currDevice = [UIDevice currentDevice]; 
[currDevice beginGeneratingDeviceOrientationNotifications]; 

然後,用得到的方位:

currDevice.orientation 

這些返回的值:

{ '1': 'Portrait', '2':'PortraitUpsideDown', '3':'LandscapeLeft', '4':'Landsc apeRight」, ‘5’:‘面朝上’, ‘6’:‘面朝下’}

+0

所以在你的情況,你會想聽currDevice.orientation是6 – JCox

+0

我必須得到的方向== 2.謝謝,這幫助我解決它。 – user773578

+0

很高興我能幫上忙! – JCox