I have a very simple view of a container that contains a sidebar and collapses the view controllers in the content area (think UISplitView, but with a small sidebar / vertical UITabBar).
The container controller also uses autoLayout when resized properly. Content viewController 1 uses autorun and was created with IB, so it has an xib file. Content viewController 2 inherits from UITableViewController and does not use xib.
If I assign viewController 1 as the root view controller and turn around, it will resize, and here are the callbacks I receive in viewController 1:
- willRotateToInterfaceOrientation
- updateViewConstraints
- viewWillLayoutSubviews
- didRotateFromInterfaceOrientation
However, if I assign the container controller as the root view controller, load viewController 1 and rotate, the size will not work. And I only get the following callbacks inside viewController 1:
- willRotateToInterfaceOrientation
- didRotateFromInterfaceOrientation
Inside the view controller container, here is how I change the view controllers:
[self addChildViewController:toViewController]; [toViewController didMoveToParentViewController:self]; // Remove the old view controller [fromViewController willMoveToParentViewController:nil]; [fromViewController.view removeFromSuperview]; [fromViewController removeFromParentViewController]; // Add the new view [self.contentContainerView addSubview:toViewController.view];
Now I get the callbacks that should happen, but it looks like neither updateViewConstraints nor viewWillLayoutSubviews are being called. This explains why the resizing does not happen, but why these methods are not called when I put the view controller in the container view?
I also tried explicitly returning YES to my container on
shouldAutomaticallyForwardAppearanceMethods
and
shouldAutomaticallyForwardAppearanceMethods
although this should already be the default.
In addition, a view controller not executed with IB (view controller 2) resizes correctly when rotated inside the container. However, I do not explicitly use NSLayoutConstraints for this, so I suspect it is the default for Springs and Struts to resize when rotated.
Do I need to forward some other events in the container of the View controller in order to get the right resizing of the view controller when rotating?