How to set AViewController (subclass of TabBar and Nav Controller) to portrait only

54 views Asked by At

If I have AViewController which is a subclass of TabBarController and NavigationController, is it possible to set it to portrait? while, the other ViewController can rotate normally. (Portrait and Landscape)

Thank you

1

There are 1 answers

4
mrt On

Yes it is. You can find the documentation here. You just have to override a few methods and return supported orientations for each view controller, such as supportedInterfaceOrientations and preferredInterfaceOrientationForPresentation methods.

For example, to limit the orientation to portrait you would do

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    return interfaceOrientation == UIInterfaceOrientationPortrait;
}

Edit:

I added the preferredInterfaceOrientationForPresentation method. Try this. This is the exact code i'm using in one of our apps, and it is working for us.