Possible Duplicate:
iPhone orientation
How to check the orientation of device at any point off time programmatically in iPhone ?
Thank You.
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.
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 }
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 }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With