0

我正在创建一个需要根据设备移动移动 uiview 的应用程序。正如我研究的那样,这可以通过使用核心运动套件来完成。当我使用 accelerometerData、gyroData、deviceMotion 来获取运动值但我无法计算如何使用这些值来移动 uiview。

if let accelerometerData = motionManager.accelerometerData {

    xAcc = round(accelerometerData.acceleration.x * 100)/100
    yAcc = round(accelerometerData.acceleration.y * 100)/100
    zAcc = round(accelerometerData.acceleration.z * 100)/100

}

if let gyroData = motionManager.gyroData {

    xGyro = round(gyroData.rotationRate.x * 100)/100
    yGyro = round(gyroData.rotationRate.y * 100)/100
    zGyro = round(gyroData.rotationRate.z * 100)/100

}

self.movement_view.frame.origin.x += xGyro
self.movement_view.frame.origin.y += yGyro

简而言之,根据这些值,视图应该在 x 或 y 方向上移动多少。

提前感谢大家。

4

0 回答 0