4

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

[[UIDevice currentDevice]orientation]

[[UIApplication sharedApplication] statusBarOrientation]

Arun
  • 3,406
  • 4
  • 30
  • 55
  • Possibly duplicate question: http://stackoverflow.com/questions/2518695/how-to-get-iphones-current-orientation http://stackoverflow.com/questions/5559652/how-do-i-detect-the-orientation-of-the-device-on-ios – Mrunal Apr 02 '13 at 05:08

2 Answers2

2

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

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

[[UIDevice currentDevice]orientation]

sometimes you get unknown orientation.

I hope that works for you.

Rajat
  • 1,378
  • 4
  • 17
  • 33
karan singh rajpoot
  • 5,401
  • 1
  • 15
  • 12
0

you can use below code:

if (UIInterfaceOrientationIsLandscape([[UIDevice currentDevice] orientation]))
{
     NSLog(@"-Landscape");
}
 else 
{
     NSLog(@"-Portrait");
}
ScarletWitch
  • 522
  • 6
  • 23
Nims
  • 431
  • 6
  • 15