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?
@implementation UINavigationController (autorotate)
Here are my "five cents", tested on iOS7 with ARC
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.
Try this...It worked out for me...
This code is for iOS 8 or later
This works for iOS7, force autorotate to portrait.
NOTE: I implemented this option in my app, but probably would get rejected by Apple (comment for Austin for edited 6 of Sergey K. in oct 2012).
Apple made changing the device orientation programmatically in ios6 quite difficult (on purpose mind you).
As far as I know the only way to accomplish what you're asking is to simulate the change of device orientation.
Using
setTransform
to rotate theUIView
and re-applying its own frame gives the desired results.And when the device physical orientation changes we can undo the transformation.