Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get iPhones current orientation?

Is there a special method to get iPhones orientation? I don't need it in degrees or radians, I want it to return an UIInterfaceOrientation object. I just need it for an if-else construction like

if(currentOrientation==UIInterfaceOrientationPortrait ||currentOrientation==UIInterfaceOrientationPortraitUpsideDown) { //Code }   if (currentOrientation==UIInterfaceOrientationLandscapeRight ||currentOrientation==UIInterfaceOrientationLandscapeLeft ) { //Code } 

Thanks in advance!

like image 207
Knodel Avatar asked Mar 25 '10 19:03

Knodel


People also ask

Why is my phone screen not rotating?

To adjust the screen rotation settings: Swipe down from the top of the screen to open the Quick settings panel. Look for the screen orientation icon. Depending on your settings, you may need to look for the Portrait, Landscape, or Auto Rotate icon.


1 Answers

This is most likely what you want:

UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation]; 

You can then use system macros like:

if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) {  } 

If you want the device orientation use:

UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation]; 

This includes enumerations like UIDeviceOrientationFaceUp and UIDeviceOrientationFaceDown

like image 175
Satyajit Avatar answered Nov 09 '22 11:11

Satyajit