5

My app has view controllers subclassing shouldautorotateToInterfaceOrientation. And in it, I decides each view's rotation. This works correctly. But in iOS6, though I read documents provided Apple, I can't understand it.

My app has navigation controller as root view controller. This navigation controller has tab controller. And the tab controller has some view controllers. I want the first view controller (in tab controller) viewed only as portrait mode and the second view controller (in tab controller) viewed both portrait and landscape mode. It works correctly in iOS5. But I don't know how to make it in iOS6. Although I know I should subclass supportedInterfaceOrientations, it doesn't work when rotation happen. To my surprise it is called when a view is showing. How to make what I want?

Thank you for reading.

eon
  • 273
  • 1
  • 5
  • 10
  • you should define the supported orientation for you application in `-application:supportedInterfaceOrientationsForWindow:` of the `AppDelegate.m` file or in the `Info.plist` and the your views would response only the `-shouldAutorotate:` method with a `BOOL` value, if your view supports the predefined orientations or not. the `- shouldAutorotateToInterfaceOrientation:` is deprecated in iOS6. – holex Oct 01 '12 at 08:02

3 Answers3

8

The following link might steer you to the right direction: http://code.shabz.co/post/32051014482/ios-6-supportedorientations-with-uinavigationcontroller

Basically, you need to subclass UINavigationController and have it listen to changes in -supportedInterfaceOrientations of its topViewController. There is a sample class you can download in the blog post and also explains what code to add.

shabbirv
  • 8,958
  • 4
  • 33
  • 34
0

When you use UINavigationController or UITabbarViewController - application always does what they say in their shouldAutorotate, supportedInterfaceOrientations methods.

You can add a category for them to redirect these methods to the controller they currently display. Like this:

 @implementation UINavigationController (Rotation_IOS6)
-(BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations
{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
@end

Similar for UITabbarViewController.

krafter
  • 1,425
  • 1
  • 15
  • 28
  • This may have unintended side effects. Think about it if you do that then that's the behavior of ALL navigation controllers system-wide, even if they're presented by the OS. I got a crash because of that. Subclassing is better because you remain in control of who gets the special behavior and who doesn't. – n13 Mar 03 '13 at 03:48
0

In my opinion, this is the best explaination i have found : http://www.widemann.net/wp-fr/?p=662 but it's in french.

Maybe it makes sense with google traduction in english

lefakir
  • 3,983
  • 4
  • 27
  • 37