立即检测iOS方向的变化 [英] Detecting iOS orientation change instantly

查看:110
本文介绍了立即检测iOS方向的变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个游戏,其中设备的方向会影响游戏的状态。用户必须在横向,纵向和反向横向方向之间快速切换。到目前为止,我一直在通过以下方式注册游戏进行定向通知:

I have a game in which the orientation of the device affects the state of the game. The user must quickly switch between Landscape, Portrait, and Reverse Landscape orientations. So far I've been registering the game for orientation notifications via:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

但它太慢了 - 旋转手机和手机之间似乎有大约第二个延迟通知实际上被解雇了。我需要一种方法来立即检测设备方向的变化。我已经尝试过使用陀螺仪进行试验,但我还不熟悉它,知道它是否是我正在寻找的解决方案。

But it is far too slow - there seems to be about a second delay between rotating the phone and the notification actually being fired. I need a way to INSTANTLY detect changes in the device's orientation. I have tried experimenting with the gyroscope, but am not yet familiar enough with it to know whether or not it is the solution I am looking for.

推荐答案

您正在谈论的延迟实际上是一个过滤器,用于防止错误(不需要的)方向更改通知。

That delay you're talking about is actually a filter to prevent false (unwanted) orientation change notifications.

For <强烈>即时识别设备方向变化你必须自己监控加速度计。

For instant recognition of device orientation change you're just gonna have to monitor the accelerometer yourself.

加速度计测量所有3轴的加速度(包括重力)所以你在确定实际方向时不应该有任何问题。

Accelerometer measures acceleration (gravity included) in all 3 axes so you shouldn't have any problems in figuring out the actual orientation.

开始使用加速度计的一些代码可以在这里找到:

Some code to start working with accelerometer can be found here:

如何制作iPhone应用程序 - 第5部分:加速度计

这个不错的博客涵盖了数学部分:

And this nice blog covers the math part:

使用加速度计

这篇关于立即检测iOS方向的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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