例如:app运行并且我们初始化起始坐标(x=0, y=0, z=0
)并且坐标系在启动时等于设备坐标系,然后它必须是固定的,即不连接到设备。我希望在x, y, z
事件被解雇的每个时刻确定MotionManager
:
motionManager.startDeviceMotionUpdates(to: OperationQueue.current!) { data, error in
x = ...
y = ...
z = ...
}
但我不知道该怎么做。
提前致谢!
答案 0 :(得分:0)
使用它像:
motionManger.startDeviceMotionUpdates(to: OperationQueue.current!) { (deviceMotion, deviceMotionError) in
self.handleDeviceMotionUpdates(deviceMotion!)
}
func handleDeviceMotionUpdates(_ deviceMotion: CMDeviceMotion){
let acceleration = deviceMotion.gravity
print("Acceleration X>\(acceleration.x) Y>\(acceleration.y) Z>\(acceleration.z)\n")
let userAcceleration = deviceMotion.userAcceleration
print("User Acceleration X>\(userAcceleration.x) Y>\(userAcceleration.y) Z>\(userAcceleration.z)\n")
}