ino*_*nik 4 ios core-motion ios11
iOS 11 中有一个新的 CMDeviceMotion标题属性。
我正在尝试使用它,但发现它总是-1.0. 它应该将度数保存为 Double from 0.0to 360.0。
我的应用面向 iOS 11+,我正在运行 iOS 11 的物理设备 (iPhone) 上进行测试。
let mmgr = CMMotionManager()
mmgr.showsDeviceMovementDisplay = true // for calibrating magnetometer, maybe not needed?
mmgr.deviceMotionUpdateInterval = 0.1
mmgr.startDeviceMotionUpdates(to: .main, withHandler: { (motionData: CMDeviceMotion?, error: Error?) in
if let motion = motionData {
print("heading:", motion.heading) // always -1.0
}
})
Run Code Online (Sandbox Code Playgroud)
我可以很好地获得其他属性,例如motion.attitude.roll. 有什么我想念的吗?
问题是我需要使用不同的方法签名开始运动更新,其中包括以下CMAttitudeReferenceFrame选项:
let mmgr = CMMotionManager()
mmgr.deviceMotionUpdateInterval = 0.1
mmgr.startDeviceMotionUpdates(using: .xMagneticNorthZVertical, to: .main, withHandler: { (motionData: CMDeviceMotion?, error: Error?) in
if let motion = motionData {
print("heading:", motion.heading) // works
}
})
Run Code Online (Sandbox Code Playgroud)
该新增iOS中11指南指出,如果使用xArbitraryZVertical(默认)或xArbitraryCorrectedZVertical为CMAttitudeReferenceFrame选项,标题将始终是-1。
这个有用的花絮未在heading属性参考中说明。
| 归档时间: |
|
| 查看次数: |
590 次 |
| 最近记录: |