iphone - 在 iPhone/iPad 上检测 180 度翻转

标签 iphone ios orientation

我正在对我的 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/

相关文章:

IOS - 获取通知并决定做什么

android - 如何在android中仅在横向模式下旋转显示?

android - 方向改变时手势清除

android - 始终横向查看对话框

ios - 如何隐藏我 View 顶部的 "internet tethering"横幅?

iphone - 如何使用 Storyboard通过自定义图像设置 iphone 标签栏图标

iphone - 增加标签栏项目之一的高度

ios - 使用应用锁 MDM 配置文件检测 iOS 应用

ios - 在 iOS 中流式传输音频文件

ios - 参数标签 "(attributes:)"与 DispatchQueue 中的任何可用重载都不匹配