iOS device orientation disregarding orientation lock

后端 未结 10 1309
天涯浪人
天涯浪人 2020-11-29 01:59

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

[UIDevice currentDevice].orientation

works as long as the device isn\'t

10条回答
  •  醉酒成梦
    2020-11-29 02:45

    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.

    To answer your question, there is no way to read the raw values from the accelerometer, without using private APIs.

    Edit:

    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.

提交回复
热议问题