Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine UIInterfaceOrientation on iPad

I don't need to specify the orientation in this case, I just need to detect it, but I'm having trouble. I have conditional code that should only work in portrait, and if the device is in landscape I need to do something else. Since the deviceOrientation is not necessarily the same as the interfaceOrientation, I can't come up with a way to test for portrait mode.

Most tutorials I find on Google are ways to force landscape or do some sort of rotation. The only thing I want to do is just determine what the orientation is. Here is my code, which is not working:

-(void)viewDidLoad {     [super viewDidLoad];     //currentOrientation is declared as UIInterfaceOrientation currentOrientation     currentOrientation = [[UIApplication sharedApplication] statusBarOrientation]; NSLog(@"%@",currentOrientation);  // == NULL } 

I need to determine the value of the interfaceOrientation and program conditionally. Thanks for your help!

like image 639
Daddy Avatar asked Apr 10 '10 17:04

Daddy


1 Answers

Are you aware of the interfaceOrientation property of the UIViewController class?

- (void) viewDidLoad {     [super viewDidLoad];     BOOL isPortrait = UIDeviceOrientationIsPortrait(self.interfaceOrientation);     // now do whatever you need } 

Or are you after [[UIDevice currentDevice] orientation]?

like image 97
zoul Avatar answered Sep 23 '22 00:09

zoul