Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In iOS6, trouble forcing ViewController to certain interfaceOrientation when pushed on stack

I have the following view controller set up:

viewController1 is able rotate freely to any orientation except portrait upside down.

viewController2 gets pushed on top of viewController1, and I'd like for it to be the same orientation viewController1 is and I'd like for it not to be able to rotate.

viewController3 gets pushed on top of viewController2. I'd like for viewController3 to be in portrait mode.

I'm having a lot of issues trying to accomplish this in iOS6 (haven't tried yet in iOS5). First off, I have already created my own Navigation Controller and put the following in it:

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [self.topViewController preferredInterfaceOrientationForPresentation];
}

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

- (BOOL) shouldAutorotate
{
    return [self.topViewController shouldAutorotate];
}

I've tried a lot of different combinations of these things to know avail. Mainly where I'm struggling is forcing vc3 to be presented as portrait if vc2 is in landscape. Any help would be appreciated.

like image 897
Ser Pounce Avatar asked Mar 08 '13 18:03

Ser Pounce


1 Answers

What you're trying to do here is fighting the framework. What you're describing is simply not how a navigation controller architecture works in iOS 6. If you want to show a view controller's view and force rotation, use a presented view controller. That's the only time preferredInterfaceOrientationForPresentation is meaningful, and your view controller's supportedInterfaceOrientations will actually be consulted because, being presented, it will be at the root of the interface.

like image 94
matt Avatar answered Oct 01 '22 20:10

matt