Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current orientation of device programmatically in iOS 6?

I have developed an iOS App and tested it on iOS6 device. While testing, I realized that my App is not responding to Orientation changes as expected.

Here is my Code:

// Autorotation (iOS >= 6.0) - (BOOL) shouldAutorotate {     return NO; }  - (NSUInteger)supportedInterfaceOrientations {     return UIInterfaceOrientationMaskAll; }  - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {     return UIInterfaceOrientationMaskPortrait; } 

Precisely, I want to know that what Methods are called on Orientation Changes in iOS.

like image 988
Code Hunter Avatar asked Dec 12 '12 09:12

Code Hunter


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

You can try this, may help you out:

How to change the device orientation programmatically in iOS 6

OR

Objective-c:

UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation] 

Swift:

if UIDevice.current.orientation.isLandscape {     // Landscape mode } else {     // Portrait mode } 
like image 119
Shekhar Gupta Avatar answered Sep 22 '22 13:09

Shekhar Gupta


You can try this, which solves your problem.

UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 

Refer below link for App extension Get device current orientation (App Extension)

like image 23
Girish Avatar answered Sep 19 '22 13:09

Girish