What is the best way to get the current orientation for setting views

I want to determine the current orientation for setting the view, which will be the best way for it from the methods described below, and how?

[[UIDevice currentDevice]orientation]

[[UIApplication sharedApplication] statusBarOrientation]

+4
source share
2 answers

You can use [[UIApplication sharedApplication] statusBarOrientation] to determine device orientation.

This method returns the orientation value for all cases, but if you use

[[UIDevice currentDevice]orientation]

sometimes you get an unknown orientation.

I hope this works for you.

+2
source

you can use the code below:

 if (UIInterfaceOrientationIsLandscape([[UIDevice currentDevice] orientation])) { NSLog(@"-Landscape"); } else { NSLog(@"-Portrait"); } 
0
source

All Articles