Two ViewControllers Orientation

382 views Asked by At

I've come up with a strange scenario, I'm using one NavigationViewController and one ViewController (named- container) in my MainWindow.xib.

NavigationController loads subsequent views, and in parallel, the other ViewController (container) loads some images on top of everything - No matter what view is displayed by the NavigationViewController.

When I rotate the device, the subsequent views of NavigationController rotates as expected but the container and its subsequent views do not rotate.

Here is the screenshot of my MainWindow.xib

enter image description here

and here is the code.

in .h

UINavigationController *navigationController;
IBOutlet UIViewController *container;

in .m (ApplicationDidFinishLaunchingWithOptions)

[window addSubview:navigationController.view];
[window addSubview:container.view];
[window makeKeyAndVisible];

I've also tried creating a separate class and assigned it to the viewController. (Its ViewDidLoad) Method fires but it doesn't come in the (ShouldRotateToInterfaceOrientation)

I read somewhere that IOS doesn't support the orientation for multiple ViewControllers.

2

There are 2 answers

2
Ankit Gupta On BEST ANSWER

I think you should try this because you are trying to use tow views in one navigation.So dont make sub view of window,make subview of main View like:-

[window addSubview:navigationController.view];
 [navigationController.view addSubview:container.view];
[window makeKeyAndVisible];

I have't try this code but i am just suggesting idea. thanks.

1
lnafziger On

There should only be one viewController to a screen, unless you are using container views.

See the Implementing a Container View Controller section of the class reference.

The very short version is that you need to create your own container and then add the two view controllers to it using the methods that they describe:

Here are the essential methods you might need to call:

  • addChildViewController:
  • removeFromParentViewController
  • transitionFromViewController:toViewController:duration:options:animations:completion:
  • willMoveToParentViewController:
  • didMoveToParentViewController: