Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the device orientation programmatically in iOS 6 [duplicate]

In iOS 5 we could change the device orientation programmatically like so:

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight]; 

But in iOS 6 setOrientation is deprecated, how may i change the device orientation programmatically in iOS 6?

like image 914
uttam Avatar asked Sep 29 '12 05:09

uttam


People also ask

How do I change orientation in IOS?

Swipe down from the top-right corner of your screen to open Control Center. Tap the Portrait Orientation Lock button to make sure that it's off. Turn your iPhone sideways.

How do I change the orientation of Xcode?

Open project in Xcode ( ios/Runner. xcworkspace ), choose Runner in the project navigator, select Target Runner and on Tab General in section Deployment Info we can setup Device Orientation : Setup a device orientation in Xcode.


1 Answers

Here are my "five cents", tested on iOS7 with ARC

[[UIDevice currentDevice] setValue:                       [NSNumber numberWithInteger: UIInterfaceOrientationPortrait]                             forKey:@"orientation"]; 

This doesnt generate "leak" warning as performSelector will.

UIAlertView - with this code, when you open UIAlertView during view(will/Did)appear you will notice that all but this view is in portrait (apple, really?) I wasn't able to force the view to reorient but found that if you put slight delay before opening the UIAlertView then view has time to change orientation.

Note I'm releasing my app week commencing 12/09/2014 and I will update post if it will pass or fail.

like image 167
Lukasz 'Severiaan' Grela Avatar answered Oct 09 '22 05:10

Lukasz 'Severiaan' Grela