5

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?

MB.
  • 4,167
  • 8
  • 52
  • 79
  • 1
    under NDA - can't be answered. –  Aug 25 '12 at 21:57
  • 14
    Come on people, there's no need to pile on downvotes for any question about iOS 6. If something's still under NDA, just politely direct people to the developer forums. No need to get hostile. – Brad Larson Aug 26 '12 at 16:14
  • I believe this answers the question better: http://stackoverflow.com/questions/12640870/ios-6-force-device-orientation-to-landscape – Thomas Tempelmann Mar 11 '14 at 00:32

3 Answers3

7

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.

JP Illanes
  • 3,665
  • 39
  • 56
  • Is not my solution, I just updated it to the new obj-c style. – JP Illanes Oct 05 '12 at 13:37
  • Doesn't seem to work for me. In any case, don't forget to release the view controller. – Ivan Vučica Oct 09 '12 at 13:39
  • Use ARC! And sorry if is dosen't work for you, this is just a ugly trick, sometimes work somes dosen't, at least for me in iOS 6 works half of the times, and actually if you build your App with xcode 4.4, seems to work most of the times (but doen't with xcode 4.5) – JP Illanes Oct 09 '12 at 14:15
2

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];
}];
1

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

beryllium
  • 29,669
  • 15
  • 106
  • 125