1

My iPad app has a UIViewController called MainViewController which presents a modal page sheet UIViewController called ModalViewController. ModalViewController then presents a UIImagePickerController.

Here is MainViewController.m:

@implementation MainViewController {

...

- (BOOL)shouldAutorotate
{
    return YES;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeRight;
}

...

}

So it rotates to either of the landscape orientations, and when ModalViewController is presented it rotates that correctly also.

However when the UIImagePickerController is presented, it allows rotation to landscape or portrait orientations, and this allows MainViewController and ModalViewController to rotate to un-desired orientations.

How can I prevent MainViewController and ModalViewController from rotating when the UIImagePickerController is on the screen?

Rahul Patel
  • 5,858
  • 6
  • 46
  • 72
Josh
  • 3,445
  • 5
  • 37
  • 55

1 Answers1

0

Is this the same problem asked here Stop a modal UIViewController from rotating ? If you're using a UINavigationController in the end you can subclass it and control the mechanism for rotation

Community
  • 1
  • 1
Vik
  • 1,897
  • 12
  • 18
  • No that's not the same problem. I've already subclass the container view controllers so that it delegates rotation to the top-most view controller. The problem is that I want the camera modal to rotate to any orientation but I need the controllers behind it not to rotate, or at least end up in the correction orientation when the camera modal is dismissed. – Josh Sep 02 '13 at 09:25
  • Oh ok, I see. Then if you still want to allow the UIImagePicker controller to rotate but you don't want that for the underlying controllers, have you considered rotating the layer for these? You could check in the rotation callback if the orientation is one that you intend to support and if it's not the case, you can just rotate the layer so that in the end it's still "displayed" as you want it to. – Vik Sep 02 '13 at 09:28
  • Is this a "correct" way of doing things? I'm concerned that the status bar wouldn't necessarily be in the correct place, and `self.view.frame` wouldn't be as expected. – Josh Sep 02 '13 at 09:41