2
votes

SOLVED:

The only way to get around this problem (as far as I can tell) is to take your free rotating view controller outside of the hierarchy. One way to do this, is to temporarily assign your freely rotating controller to the app delegate rootcontroller. This way, when it rotates, the rest of your hierarchy will not be affected.


I have a controller which I push and the supportedInterfaceOrientations is called properly and the value is returned properly - I am forcing portrait orientation. I have subclassed my navigator and tab controllers, so I am getting the relevant methods called fine. In fact everything works perfectly, except this one issue:

From a particular controller, which supports only portrait, I push another one, which supports all orientations.

While in this second controller, if I change the device to landscape, and then pop this controller while in landscape mode, the following occurs:

In my original controller, supportedInterfaceOrientations is called fine (shouldAutorotate is returning YES) and the same orientation value as before (portrait only) is returned. However, even though I pass porrtait only, the content of the controller is still landscape.

With break points, I have verified that supportedInterfaceOrientations is called every time. However, the returned value is not applied when a child controller landscape controller is popped.

I have tried adding [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait]; in viewWillAppear, but: 1) It does not work and, 2) Will this not get my app rejected?

How can I solve this problem?

EDIT, here is some code, although my problem is very basic.

in controller 1, these are ALWAYS called:

-(BOOL)shouldAutorotate{
    return NO;
    ///return YES; // does not matter
}


-(NSUInteger)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskPortrait;

}

then, at some point I push my second controller (it;s a video player):

[self presentModalViewController:playerController animated:YES];

in controller 2:

-(BOOL)shouldAutorotate{
    return YES;
}


-(NSUInteger)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskAll;

}

step to repeat:

1) launch app , it will show controller 1 in portrait mode as that's the mask returned. And it will not rotate.

2) push (or even present modaly) controller 2.

3) This one will rotate. Rotate to landscape mode.

4) pop controller 2.

5) controller 1 will be in landscape mode, even though, shouldAutorotate and supportedInterfaceOrientations are called and they return the values as shown in code for controller 1.

1
Maybe you could show some of your code?Zane
added code, the principle is very simple and even happens in plain projects: show a root controller which restricts orientation to portrait. then push a controller which does not restrict it. Then, rotate to landscape pushed controller and pop it. The root controller will be in landscape mode, even though the two methods are called and portrait is forced.Stav Katsoulis
Seems you found a solution - not sure, but I think it is possible to answer your own question and vote for your own answer. Maybe you want to do this.Zane

1 Answers

0
votes
//add code in your controller 1

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}