0

I have UITableViewController in which on one tab is UINavigationViewController. UINavigationController root view controller is UITableViewController, and when clicked on cell, UIViewController appears which has to be locked in Landscape.

I want every Controller to be locked in Portrait, except the mentioned UIViewController that must be locked in Portrait.

I have tried the following:

CustomTabBarController.m:

#import "CustomTabBarController.h"

@implementation CustomTabBarController

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // You do not need this method if you are not supporting earlier iOS Versions
    return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}

- (BOOL)shouldAutorotate{
    return YES;
}

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

@end

CustomNavigationController.h:

#import "CustomNavigationController.h"

@implementation CustomNavigationController

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

-(BOOL)shouldAutorotate
{
    return YES;
}

@end

And in UIViewController that must be locked in to Landscape, I have put:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

-(BOOL)shouldAutorotate
{
    return YES;
}

But it doesn't work, I can rotate it to Landscape and it will stay locked in Landscape, but I want it to appear automatically in Landscape.

Any suggestions?

Arun
  • 3,406
  • 4
  • 30
  • 55
1337code
  • 385
  • 1
  • 6
  • 19

3 Answers3

0

I had a big problem in the past with UITabBarController not respecting my supported interface orientations of displayed view controllers.

I solved the problem by sub-classing UITabBarController and capturing whenever an item was selected. I'd then call down to the view controller myself, ask it what the supported orientations are and force a rotation myself if needed. I would also call down to the selected view controller on rotations to set/change my supported orientations.

I implemented the UITabBarDelegate and used didSelectItem to capture tab switches. I'm not sure if there is a better way to do it now.

DBD
  • 23,075
  • 12
  • 60
  • 84
0

Try to override method

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

Stas
  • 641
  • 8
  • 16
0

Try with the method to block some orientations for a particular window:

– application:supportedInterfaceOrientationsForWindow:
nabrugir
  • 1,839
  • 2
  • 22
  • 38