문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top