Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 6 force an orientation

Tags:

ios

ios6

ios5

In iOS5 you could use this snippet to force the orientation:

UIViewController *c = [[UIViewController alloc]init];
[self presentModalViewController:c animated:NO];
[self dismissModalViewControllerAnimated:NO];
[c release];

However this causes an EXC_BAD_ACCESS in iOS6. How can a certain orientation be forced in iOS6?

like image 427
MB. Avatar asked Aug 25 '12 21:08

MB.


People also ask

How do I force landscape in iOS?

On an iPhone with a Home button, swipe up from the bottom of the screen to access it. On an iPhone without a Home button, swipe down from the top-right corner of the screen instead. Here, tap on the rotation lock icon (which looks like a lock with a circular arrow) to turn it on or off.

How do I force an app to rotate?

Android Settings Start by going to Settings => Display and locate the “Device rotation” setting. On my personal cell phone, tapping this will reveal two options: “Rotate the contents of the screen,” and “Stay in portrait view.”

Why won't my iPhone screen rotate even when unlocked?

How Do I Fix It? Swipe down from the top-right corner of the screen on an iPhone or iPad to open the Control Center, then tap the small lock icon to allow for screen rotation. If this doesn't work, try restarting the app or restarting your iPhone or iPad.

How do I change orientation mode?

Select the Start button, then type settings. Select Settings > System > Display, and choose a screen orientation from the drop-down list next to Display orientation.


3 Answers

Just to complete the previous answer, you should do this:

UIViewController *viewController = [[UIViewController alloc] init];
[self presentViewController:viewController animated:NO completion:^{
    [viewController dismissModalViewControllerAnimated:NO];
}];

And iOS 6 is no longer under NDA.

like image 78
JP Illanes Avatar answered Nov 01 '22 04:11

JP Illanes


In case anyone still cares about this, here's the iOS6 code snippet (I placed it in my viewDidLoad routine):

UIViewController *viewController    = [[UIViewController alloc] init];
viewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:viewController animated:NO completion:^{
    [self dismissViewControllerAnimated:NO completion:nil];
}];
like image 43
Christopher Shortt Avatar answered Nov 01 '22 05:11

Christopher Shortt


At first presentModalViewController and dismissModalViewControllerAnimated are deprecated and probably iOS6 will not use these methods correctly. You should use similar methods with complition block instead.

The second thing is that [self dismissModalViewControllerAnimated:NO]; tries to dismiss self firstly. Is this correct in your case?

And last thing iOS6 is under NDA

like image 1
beryllium Avatar answered Nov 01 '22 03:11

beryllium