iOS - 陀螺仪示例
我正在寻找编写一个以“拉”方式使用陀螺仪的代码。我找到了使用 startGyroUpdatesToQueue:withHandler: [“Push”方法] 的示例代码。 我希望改用 startGyroUpdates 。我想在屏幕上连续显示陀螺仪更新,而不使用 startGyroUpdatesToQueue:withHandler: 这可能吗?如果有的话,有什么样本可以参考吗?
提前致谢
I am looking for writing a code which makes use of Gyroscope in 'pull' fashion. I fid sample code which makes use of startGyroUpdatesToQueue:withHandler: [ "Push' approach ].
I wish to make use of startGyroUpdates instead. I want to display the gyro updates continuously on screen without using startGyroUpdatesToQueue:withHandler:
Is this possible? If yes, is there any sample I can refer to.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这非常简单。要开始使用,您应该阅读事件处理指南,尤其是 处理已处理的设备运动数据。
您只需保留对 CMMotionManager 的引用,然后在您的 drawView 方法中读取
motionManager.deviceMotion.attitude
- 更复杂的方法是将其放入自己的线程中,但在大多数情况下没有需要这样做。 CMAttitude 为您提供欧拉角(俯仰角、横滚角、偏航角)、旋转矩阵或陀螺仪更新的四元数表示。 CMDeviceMotion 包含时间戳。您可以在 WWDC 2010 会议视频的茶壶演示中找到示例代码,请查看我的回答
iPhone 4 上的 CMMotionManager 和陀螺仪。处理是在 EAGLView 中完成的,尽管他们做了更多加速计的东西来显示差异,但您会发现 referenceAttitude 的设置和使用。
It's pretty straightforward. To get startet you should read the Event Handling Guide especially the section Handling Processed Device-Motion Data.
You just have to keep a reference to CMMotionManager and then read
motionManager.deviceMotion.attitude
for example in your drawView method - a more sophisticated approach is putting it into an own thread, but in most cases there is no need to do it that way. CMAttitude provides you with Euler angles (pitch, roll, yaw), rotation matrix or quaternion representation of the gyro updates. CMDeviceMotion contains the timestamp.You can find sample code in the teapot demo from the WWDC 2010 session videos, look at my answer in
CMMotionManager and the Gyroscope on iPhone 4. Processing is done in EAGLView and although they do more accelerometer stuff to show the difference, you will find the set up and usage of referenceAttitude.