Reputation: 1161
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
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
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