iOS-开始接收陀螺仪更新

标签 ios gyroscope

我使用 CMMotionManager 来访问 iOS 的陀螺仪数据。我看到有两种方法:

startGyroUpdates 
startGyroUpdatesToQueue:withHandler:

开始接收陀螺仪更新。我们如何区分调用这两种方法。它们中的任何一个都可以调用的情况是什么?一个比另一个重要吗?

感谢任何帮助,

最佳答案

队列用于保证所有事件都得到处理,即使您在deviceMotionUpdateInterval 中设置的更新间隔也是如此。以比您实时处理的速度更快的速度生成事件。如果您不介意丢失事件,那么使用两者中的哪一个都没有关系,只需丢弃它们即可。

相关的 Apple 文档是 Core Motion事件处理指南部分:

For each of the data-motion types described above, the CMMotionManager class offers two approaches for obtaining motion data, a push approach and a pull approach:

  • Push. An application requests an update interval and implements a block (of a specific type) for handling the motion data; it then starts updates for that type of motion data, passing into Core Motion an operation queue as well as the block. Core Motion delivers each update to the block, which executes as a task in the operation queue.

  • Pull. An application starts updates of a type of motion data and periodically samples the most recent measurement of motion data.

The pull approach is the recommended approach for most applications, especially games; it is generally more efficient and requires less code. The push approach is appropriate for data-collection applications and similar applications that cannot miss a sample measurement.

这不是你的问题,但我想知道你是想要原始的 x、y、z 旋转还是更有用的 pitch、roll、yaw。以备后用startDeviceMotionUpdatesToQueue:withHandler:相反 startGyroUpdatesToQueue:withHandler: .

关于iOS-开始接收陀螺仪更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7235541/

相关文章:

android - Android 可穿戴设备上加速度计和陀螺仪数据的连续感知

ios - 确定设备方向及其在一个维度上的角度?

iphone - iOS 陀螺仪 API

ios - Xcode - 是否可以在 Interface Builder 中同时查看 Main.storyboard 及其源代码?

ios - iOS AVAudioPlayer无法播放

iphone - 每次应用程序进入前台时重新加载 UITableView

ios - 是否需要开发者帐户才能打开 Xcode 中的功能?

python - MPU6050中I2C工作频率与采样率设置的关系

arduino - MPU6050 与 Arduino 输出偏航俯仰和滚转

ios - VoiceOver 在 UITableView 中滚动,其中单元格和 subview 都是可访问性元素