为什么加速度值(userAcceleration)不为零,即使设备处于静止状态?我使用以下代码来确定x,y,z的加速度:
motionManager.startDeviceMotionUpdates(to: OperationQueue.current!) { [weak self] data, error in
if let error = error {
print("Error occurred: \(error)")
} else {
if let data = data,
let weakSelf = self {
weakSelf.userAccelerationByX.text = "\(data.userAcceleration.x)"
weakSelf.userAccelerationByY.text = "\(data.userAcceleration.y)"
weakSelf.userAccelerationByZ.text = "\(data.userAcceleration.z)"
}
}
}
答案 0 :(得分:0)
iPhone使用磁铁来确定加速度,因此它对一切都非常敏感。即使你把手机放下,仍有很多东西会影响它的磁性和运动。