Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check the orientation of device programmatically in iPhone? [duplicate]

Possible Duplicate:
iPhone orientation

How to check the orientation of device at any point off time programmatically in iPhone ?

Thank You.

like image 781
suse Avatar asked Aug 30 '10 12:08

suse


People also ask

How do I find the orientation of my device?

If the activity locks the display ( android:screenOrientation="portrait" ), this method will return the same value irrespective of how the user rotates the device. In that case you'd use the accelerometer or the gravity sensor to figure out orientation properly.


2 Answers

Here are macros UIDeviceOrientationIsLandscape and UIDeviceOrientationIsPortrait

so rather checking separately you can do it like this ...

   if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))     {          // code for landscape orientation           } 

OR

    if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))     {          // code for Portrait orientation            } 
like image 185
Azhar Avatar answered Sep 25 '22 13:09

Azhar


Try it.

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];  if ( ([[UIDevice currentDevice] orientation] ==  UIDeviceOrientationPortrait)  ) {    // do something for Portrait mode } else if(([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight) || ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeLeft)) {    // do something for Landscape mode } 
like image 26
Sanket Pandya Avatar answered Sep 22 '22 13:09

Sanket Pandya