【发布时间】:2016-07-02 11:58:32
【问题描述】:
是否可以使用 CoreMotion 的数据计算 iPhone 移动时的高度差?
例如,保存 iPhone 的初始位置,然后移动 iPhone,从而产生一个新位置。我有兴趣检测 iPhone 的高度是否从其初始位置移动。我不需要绝对单位,只需要一个相对值来指示高度与原始高度相比变化的百分比。
let manager = CMMotionManager()
// Save initial attitude
var initialAttitude = manager.deviceMotion.attitude
if manager.deviceMotionAvailable {
manager.startDeviceMotionUpdatesToQueue(NSOperationQueue.mainQueue()) {
[weak self] (data: CMDeviceMotion!, error: NSError!) in
// Get the difference between the initial and new attitude
data.attitude.multiplyByInverseOfAttitude(initialAttitude)
// Is there a way to calculate the relative change in height?
}
}
【问题讨论】:
标签: ios core-motion