开发者

Detecting the iPhone Device is flat

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

orientation == UIDeviceOrientationLandscapeRight
orientation == UIDeviceOrientationPortraitUpsi开发者_运维技巧deDown
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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜