我在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.
}
}
儘管您可以忽略它(請參閱@Jim Buck),但更好的方法是修復阻止您的代碼正常工作的錯誤。可能只是一件小事。 – Eiko
那麼我的數學基於以前的位置工作,所以如果以前的位置沒有移動,那麼我不想做數學...我的上面的忽略代碼不起作用,即使使用吉姆的代碼... – mootymoots
在風景檢查中,您檢查是否來自LandscapeRight或Left。在肖像中,您不檢查是否來自肖像倒立。也許更新你的代碼,讓其他人可以根據@Jim Buck指出的正確更新你的parens。 – lilbyrdie