目标是检测用户移动手机的方向。想象一下,在最简单的情况下,手机平放在桌子上,首页按钮面向天花板。iOS:检测用户移动手机左/右(不旋转,但移动)
如果用户沿着桌面向左/右滑动手机,您如何检测移动的数量?
下面的代码似乎没有登记正确的价值观:
let motionManager = CMMotionManager()
override func update(_ currentTime: TimeInterval) {
processUserMotion(forUpdate: currentTime)
}
func processUserMotion(forUpdate currentTime: CFTimeInterval) {
// 2
if let data = motionManager.accelerometerData {
// 3
if fabs(data.acceleration.x) > 0.2 {
// 4 How do you move the ship?
print("X Acceleration: \(data.acceleration.x)")
}
if fabs(data.acceleration.y) > 0.2 {
// 4 How do you move the ship?
print("Y Acceleration: \(data.acceleration.y)")
}
if fabs(data.acceleration.z) > 0.2 {
// 4 How do you move the ship?
print("Z Acceleration: \(data.acceleration.y)")
}
}
}
谢谢!实际上,这个表格的例子很有意思,简化了这个问题。一个真实的使用案例是用拇指在屏幕上一手握住手机,有点像用一只手玩游戏的标准位置。你是否从这个位置上说,ARKit现在可以让你轻松地测量用户向左/向右移动设备的次数,而在ARKit之前它并不真正实用? – Crashalot
是的,我很确定ARKit可以做到这一点,并且之前没有任何可用的东西。我没有自己使用ARKit,所以我不能说代码融入代码是多么容易,或者它有多准确,或者是否存在其他复杂性(例如,它可能很滞后,或者只能在良好的亮度级别下工作,或者如果你在繁忙的街景上使用它会感到困惑,等等,我只是不知道) – Columbo
够公平的,希望你对ARKit能够做到这一点是正确的! – Crashalot