tags:

views:

56

answers:

2

How to find when the ipod is held straight up in the air - both horizontally and vertically.

Can any one help me ?

Thanks in advance.....

+1  A: 

You would read the accelerometer values. A value of approx 1 on one axis, and approx 0 on all others would indicate that the devices was stationary and in a vertical (or horizontal) orientation : the 1 indicates 1 G acting through the plane of the device. Of course this would only work on Earth :-) I guess checking for 0 on all but one axis would eliminate that bug!

Andiih
A: 

If I understand your question, maybe with the UIDevice orientation you can know it easily.

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(orientationObserver) name: UIDeviceOrientationDidChangeNotification object: nil];

On the selector take the orientation with

UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

This way you avoid check the acceleration and know the orientation of the device.

 UIDeviceOrientationPortrait,
 UIDeviceOrientationPortraitUpsideDown,
 UIDeviceOrientationLandscapeLeft,
 UIDeviceOrientationLandscapeRight,
 UIDeviceOrientationFaceUp,
 UIDeviceOrientationFaceDown
Espuz