Question

The apple developer documentation explains the handled movement by this image :

Developer documentation

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top