I have a custom container view controller in my app, and haven't been able to achieve the same rotation behavior in iOS 6 that I had in iOS 5.
The container (call it containerVC) holds two view controllers, one that should stay in portrait (portraitVC) and one that can rotate into landscape (rotatingVC). I switch between them using a segmented control.
If I open the containerVC with portraitVC showing initially, and then rotate the phone to landscape, portraitVC correctly doesn't rotate. BUT if I switch to rotatingVC, rotate into landscape, and then switch to portraitVC while the phone is still held in landscape, portraitVC draws incorrectly draws itself in landscape.
In iOS 5, portraitVC always stays in portrait.
I have this code in the containerVC for switching view controllers:
- (IBAction)segmentChanged:(id)sender {
UIViewController *toViewController = [self viewControllerForSegmentIndex:self.selectedSegmentIndex];
[self addChildViewController:toViewController];
UIViewController *fromViewController = self.selectedViewController;
[self transitionFromViewController:self.selectedViewController
toViewController:toViewController
duration:0
options:0
animations:^{}
completion:^(BOOL finished) {
self.selectedViewController = toViewController;
[toViewController didMoveToParentViewController:self];
[fromViewController removeFromParentViewController];
}];
}
This in the containerVC to handle rotation:
- (NSUInteger)supportedInterfaceOrientations {
UIInterfaceOrientationMask mask = UIInterfaceOrientationMaskPortrait;
if ([self.selectedViewController respondsToSelector:@selector(supportedInterfaceOrientations)] ) {
mask = [self.selectedViewController supportedInterfaceOrientations];
}
return mask;
}
This in the portraitVC:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
And this in the rotatingVC:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
When I select the portraitVC after selecting the rotatingVC, none of the rotation methods or callbacks are invoked on the containerVC or portraitVC. The appearance methods are called, and the portraitVC, which holds a tableview, gets UITableViewCells with landscape geometry in the tableview callbacks.
It's not the end of the world if we have to make portraitVC support landscape, but the preference is not to if possible, for consistency with other parts of the app. Seems like there should be a way to get it to work since the built in container VCs work right when you subclass them and override supportedInterfaceOrientations.