3

In my application, I need to handle a different orientation for my ViewControllers.

  1. ViewController1 must support only landascape orientation.
  2. ViewController2 must support landscape + portrait orientation.

I enable, in Summury project, all orientations like this:

Summary project orientation

So, I insert this code in ViewController1:

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

And I insert this code in ViewController2 :

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

The problem is that ViewController1 rotates also in portrait orientation (it should support only landscape orientation).

Any idea?

Thank you all very much!

MaTTP
  • 953
  • 2
  • 12
  • 27

2 Answers2

1

Is your viewController your rootViewController ? If not, that may be your problem.

If your rootViewController is a UINavigationController, you should know that it not forward those messages to it's topViewController. So if this is your case, i suggest that you use a subclass of UINavigationController in which you override those new methods in order to forward to the topViewController.

iSofTom
  • 1,718
  • 11
  • 15
0

Before iOS 6 this works fine

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientatio n { if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) return YES;

else return NO; }

But in iOS 6 is deprecated

Now you should specify the orientations that want and select a orientation for presentation

you should write

- (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; }

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationLandscapeRight; }

Hope it helps

Good Luck

Julio Montoya
  • 1,614
  • 1
  • 12
  • 14