I have an issue with the orientation of my container controller.
When switching between controllers the previous controller tends to stay in whatever orientation it left off in when you switch back.

First, the steps I use to reproduce:
- When the container controller is presented I rotate to landscape.
Everything looks fine in landscape at this point. - Switch to child controller #2 via the segmented control.
- Rotate back to landscape in this view. Everything still looks normal.
- Switch back to child controller #1.
in ContainerController’s viewDidLoad:
self.child1 = [self.storyboard instantiateViewControllerWithIdentifier:@"first"];
self.child2 = [self.storyboard instantiateViewControllerWithIdentifier:@"second"];
[self addChildViewController:self.child1];
[self addChildViewController:self.child2];
[self.view addSubview:self.child1.view];
How I transition the child controllers:
- (IBAction)segmentChanged:(id)sender
{
UIViewController *toVc, *fromVc;
UISegmentedControl *segment = sender;
if (segment.selectedSegmentIndex == 0)
{
toVc = self.child1;
fromVc = self.child2;
}
else
{
toVc = self.child2;
fromVc = self.child1;
}
[toVc willMoveToParentViewController:self];
[self transitionFromViewController:fromVc
toViewController:toVc
duration:0.0
options:UIViewAnimationOptionTransitionNone
animations:nil
completion:^(BOOL finished){
[toVc didMoveToParentViewController:self];
}];
}
I had assumed transitionFromViewController would take care of all of that automatically. Does anyone know what I am doing wrong?
A quick solution would be to add the following line before transtionFromViewController function is called
this should set the frame in the new view correctly