iOS设备方向忽略方向锁定 [英] iOS device orientation disregarding orientation lock

查看:144
本文介绍了iOS设备方向忽略方向锁定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想查询iPhone当前的方向。使用

I want to query the orientation the iPhone is currently in. Using

[UIDevice currentDevice].orientation

只要设备没有方向锁定就可以工作。但是,如果它被锁定,它总是以锁定的方向响应,而不是设备的实际方向。

works as long as the device isn't orientation-locked. If it is locked, however, it always responds with the locked orientation, not with the actual orientation of the device.

是否有高级方法来获取实际值设备方向?

Is there a high-level way to get the actual device orientation?

推荐答案

该功能是正确的。如果它始终返回设备方向,即使它被锁定,也会触发方向更改通知。这会破坏锁定的目的。

That functionality is correct. If it always returned the device orientation, even if it was locked, the orientation changed notifications would fire. This would defeat the purpose of the lock.

为了回答你的问题,没有使用私有API就无法从加速度计读取原始值。

编辑:

在查看文档后,似乎UIAccelerometer类提供了这些数据,即使方向被锁定。此更改已应用于iOS 4及更高版本。即使您可以使用此数据,仍需要对其进行处理以确定方向。这不是一项容易的任务,因为您需要不断监视更改并将其与旧值进行比较。

After reviewing the documentation, it seems that the UIAccelerometer class provides this data, even when the orientation is locked. This change was applied in iOS 4 and above. Even though you can use this data, you still need to process it to determine the orientation. This is not an easy task as you need to monitor the changes constantly and compare them to older values.

另外,请查看本指南,用于处理动作事件。这可能为您提供另一种确定方向的途径。

Also, take a look at this guide for handling motion events. This may provide you with another route to determining the orientation.

这篇关于iOS设备方向忽略方向锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆