苹果开发人员文档解释了此图像处理的运动:

我现在很困惑......因为做了一些测试我发现加速计不处理轴上的平移,而是处理一小部分旋转...例如,如果我在 X 轴上移动设备,则不会发生任何事情..如果我将其旋转我获得加速的 Z
X
。
这是我用于测试的代码:
-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{
[self.sliderX setProgress:fabsf(acceleration.x)];
[self.sliderY setProgress:fabsf(acceleration.y)];
[self.sliderZ setProgress:fabsf(acceleration.z)];
}
编辑------
我无法理解的行为与单个轴上的旋转有关,正如我之前所说...在 Z 轴上旋转 30° 我获得连续的加速度...在 X 轴上平移时我仅获得短暂的加速度和快速移动。
The apple developer documentation explains the handled movement by this image :

I'm pretty confused now... because doing some tests i get that the Accelerometer doesn't handle translation on the axis but a little set of rotations ... in example if i move my device on the X
axe nothing happen .. if i rotate it on the Z
i get acceleration on X
.
Here the code i use for my test:
-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{
[self.sliderX setProgress:fabsf(acceleration.x)];
[self.sliderY setProgress:fabsf(acceleration.y)];
[self.sliderZ setProgress:fabsf(acceleration.z)];
}
Edit------
The behavior that i can't understand is wired to rotation on a single axe, as i said before... rotating on Z axe by 30 ° i get a continuous acceleration... while translating on X axe i get acceleration only for short and fast movement.
发布评论
评论(1)
加速度计受重力加速度的影响最为强烈。它实际上返回的是自由落体和它实际所做的任何事情之间的差异。
因此,如果您将 iPhone 平放在桌子上,您应该会沿着 z 方向产生加速度。如果你用它的长边之一来平衡它,你应该沿着 x 方向有一个加速度。如果您的 iPhone 掉落到地面,那么您的加速度矢量应该为 (0, 0, 0)。
移动 iPhone(例如滑动)会产生效果,但与重力相比,它可能很小,因此很容易被忽略。
因此,在 z 上旋转会产生持久的变化,因为您改变了相对于设备的重力方向。在 x 上平移会产生瞬态变化,因为您短暂加速设备,然后停止加速。
The accelerometer is most strongly affected by acceleration due to gravity. It's actually returning the difference between free fall and whatever it's actually doing.
So, if you had the iPhone flat on the table you should have an acceleration along z. If you balanced it on one of its longer sides, you should have an acceleration along x. If your iPhone was falling to the ground then you should have an acceleration vector of (0, 0, 0).
Moving the iPhone, such a sliding it, will produce an effect but it'll likely be small in comparison to gravity so it'll be easy to miss.
So rotating on z produces a lasting change because you've changed the direction of gravity relative to the device. Translating on x gives a transient change because you're accelerating the device briefly, then stopping the acceleration.