2

what are the correct values for detecting the device upside down?

I have the following and it starts detecting when the user has titled the device on its back.

I use the following values

float xx = -[acceleration x];
    float yy = [acceleration y];
    float angle = atan2(yy, xx);

    if(angle >= 0.75 && angle <= 2.25)
    {
        NSLog(@"Upside down");
    }
user773578
  • 1,161
  • 2
  • 13
  • 24

3 Answers3

7

Start listening for orientation events by using:

UIDevice *currDevice = [UIDevice currentDevice];
[currDevice beginGeneratingDeviceOrientationNotifications];

Then, get the orientation using:

currDevice.orientation

These are the values that are returned:

{'1' : 'Portrait', '2' : 'PortraitUpsideDown', '3' : 'LandscapeLeft', '4' : 'LandscapeRight', '5' : 'FaceUp', '6' : 'FaceDown'}

JCox
  • 86
  • 2
1

UIDevice Class Reference

See 'Getting the Device Orientation' part.

ChangUZ
  • 5,380
  • 10
  • 46
  • 64
0

this is my approach (with code) to implement device orientations handling on iOS, and you can use it if you like:

How to handle UIDeviceOrientation for manage views layouts