2011-01-09 84 views
2

我在iPhone應用程序中對從縱向到橫向的各種視圖進行了一些修改。如果用戶使用縱向 - >橫向 - >縱向 - >橫向(因爲我會做一些數學操作來重新定位視圖),這可以正常工作。在iPhone/iPad上檢測180翻轉

但是,如果用戶從Portait - >縱向顛倒,或橫向左 - >右轉,我的代碼不起作用。

我可以檢測到180翻轉並忽略它嗎?我試過如下:

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    if ((fromInterfaceOrientation == UIInterfaceOrientationPortrait) && 
     (UIDeviceOrientationIsPortrait(self.interfaceOrientation)) 
    { 
    } 
    else if ((fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) || 
      (fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight) && 
      (UIDeviceOrientationIsLandscape(self.interfaceOrientation))) 
    { 
    } 
    else 
    { 
     // Do something - it didn't flip 180. 
    } 
} 
+0

儘管您可以忽略它(請參閱@Jim Buck),但更好的方法是修復阻止您的代碼正常工作的錯誤。可能只是一件小事。 – Eiko

+0

那麼我的數學基於以前的位置工作,所以如果以前的位置沒有移動,那麼我不想做數學...我的上面的忽略代碼不起作用,即使使用吉姆的代碼... – mootymoots

+0

在風景檢查中,您檢查是否來自LandscapeRight或Left。在肖像中,您不檢查是否來自肖像倒立。也許更新你的代碼,讓其他人可以根據@Jim Buck指出的正確更新你的parens。 – lilbyrdie

回答

2

你必須在你的邏輯,這部分括號:

fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight 

..否則,你的邏輯將無法達到你的期待。 &&優先於||

+0

謝謝 - 完成了,但代碼仍然調用180度翻轉的最後一個...? – mootymoots

+0

那麼,哪種情況正在造成? '從'方向不正確,還是'至'方向不正確? –