Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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

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...

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