我正在对我的 iPhone 应用程序中从纵向到横向的各种 View 进行重新调整。如果用户执行 Portrait -> Landscape -> Portrait -> Landscape(就像我做一些数学运算一样重新定位 View ),这会很好地工作。
但是,如果用户从 Portait -> Portrait 颠倒,或 Landscape Left -> Landscape Right,我的代码将不起作用。
我可以检测到 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.
}
}
最佳答案
您需要在这部分逻辑周围加上括号:
fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight
.. 否则您的逻辑将不会像您期望的那样出现。 &&
的优先级高于 ||
。
关于iphone - 在 iPhone/iPad 上检测 180 度翻转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4641566/