【问题标题】:device orientation differs from iphone 4 to 5?设备方向从 iphone 4 到 5 不同?
【发布时间】:2014-01-27 23:44:14
【问题描述】:

我编写了一个应用程序,其中一个用例对设备方向做出反应。在我的 iPhone 5 上一切正常,但在我的测试人员 iPhone 4 上却没有任何反应。

我正在使用测试飞行检查点来查看它们没有达到翻转方法,这意味着([[UIDevice currentDevice] orientation]) 要么在不同的 iPhone 版本中返回不同的值,要么我需要用其他东西检查设备是否处于横向模式。

-(BOOL)checkDeviceOrientation
{
    BOOL orientationError = NO;
    switch ([[UIDevice currentDevice] orientation])
    {
        case UIDeviceOrientationPortraitUpsideDown:
        case UIDeviceOrientationLandscapeLeft:     
        case UIDeviceOrientationLandscapeRight:    
            [self setRotationMessage:[[UIDevice currentDevice] orientation]];
            orientationError = YES;
            break;
        default:
            break;
    }

    return orientationError;
}

有没有人遇到过同样的问题,有什么建议吗?

【问题讨论】:

  • 你在哪里检查方向?两台设备是否运行相同版本的 iOS?
  • @nhgrif 两个设备都运行相同的 ios 版本,我检查按钮单击时调用的方法内的方向
  • 请提供相关代码。
  • @Lance 没什么特别的,左右横向 ([[UIDevice currentDevice] 方向]) 上的开关盒我有一个警报。
  • 这是在特定的视图控制器或应用程序级别内吗?

标签: ios iphone objective-c device-orientation


【解决方案1】:

根据我的经验,最好检查状态栏方向而不是设备方向。设备方向是物理设备的方向,而不是 UI。

[UIApplication sharedApplication].statusBarOrientation

顺便说一句,您可能会遇到设备为UIDeviceOrientationFaceUpUIDeviceOrientationFaceDown 的情况

【讨论】:

  • Lance 我需要物理设备的方向,即用户握住手机的实际方式。我面临的问题是,在 iphone 5 中我得到了正确的值,而在 iphone 4 中我总是得到纵向。
  • 哦,明白了。是的,这没有任何意义。你确定都是 iPhone 4 还是那部手机有问题?加速度计是否有可能损坏/禁用(可能是旋转锁定?)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-10-27
  • 2011-09-27
  • 2011-06-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多