dragon
dragon

Reputation: 317

How to detect when iPhone is moving in X direction?

How do I detect that the iPhone is moving in a particular direction (X-axis)? Can you show some sample code?

Upvotes: 0

Views: 413

Answers (1)

Madhup Singh Yadav
Madhup Singh Yadav

Reputation: 8114

You can do it with help of UIAccelerometer and check the movement fo phone in x-axis by:

 - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)aceler {
        if (sqrt(aceler.x * aceler.x) > 1.5f)
        {
                  //write your code here
        }
    }

Hope this helps.

Thanks,

Madhup

Upvotes: 1

Related Questions