gpt4 book ai didi

iOS-开始接收陀螺仪更新

转载 作者:行者123 更新时间:2023-11-28 19:22:51 25 4
gpt4 key购买 nike

我使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com