user773578
user773578

Reputation: 1161

Detecting the device upside down

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");
    }

Upvotes: 2

Views: 2120

Answers (3)

user804124
user804124

Reputation:

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

Upvotes: 0

JCox
JCox

Reputation: 86

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'}

Upvotes: 7

ChangUZ
ChangUZ

Reputation: 5440

UIDevice Class Reference

See 'Getting the Device Orientation' part.

Upvotes: 1

Related Questions