views:

254

answers:

3

To detect the orientation of the phone when taking a picture I use

orientation == UIDeviceOrientationLandscapeRight
orientation == UIDeviceOrientationPortraitUpsideDown
orientation == UIDeviceOrientationPortrait
orientation == UIDeviceOrientationLandscapeLeft

But these work if the picture is being taken from the side. How do I check whether the iPhone is tilted downwards to be flat e.g. when taking an aerial picture?

A: 

Have a look at UIAccelerometer (and UIAccelerometerDelegate) classes which must be used to detect device movements.
Edit: In UIAccelerometer class reference there're links to 3 related samples: AccelorometerGraph, GLGravity and GLPaint

Vladimir
Thanks. will do.
erastusnjuki
Thanks for the Edit :)
erastusnjuki
A: 

there's a sample app on http://developer.apple.com/iphone that graphs raw data from the accelerometer. Install it on your device, and have a look at the kind of data you get.

The sample app comes with an option (I think it's "damping") that effectively cancels out gravity. You don't want to do this - in fact gravity is what's going to "accelerate" your device in the Z axis when it's flat...

Rob Fonseca-Ensor
+2  A: 

It exists other constant for the device orientation:

typedef enum {
   UIDeviceOrientationUnknown,
   UIDeviceOrientationPortrait,
   UIDeviceOrientationPortraitUpsideDown,
   UIDeviceOrientationLandscapeLeft,
   UIDeviceOrientationLandscapeRight,
   UIDeviceOrientationFaceUp,
   UIDeviceOrientationFaceDown
} UIDeviceOrientation;

You can find them here: UIDevice Class Reference

Yannick L.
This is what I was looking for +1
erastusnjuki