Question

I am developing an iPad app that should only support landscape orientation. I use these two methods to add a new child view controller to my container view controller:

- (void) assignFirstChildViewController:(UIViewController*)controller
{
    self.currentChildViewController = controller;
    [self addChildViewController:self.currentChildViewController];
    [self.currentChildViewController didMoveToParentViewController:self];
    [self.containerView addSubview:self.currentChildViewController.view];

}
- (void)assignNewChildController:(UIViewController *)childViewController
{
    id currentChildViewController = self.currentChildViewController;

    if(!currentChildViewController){
        [self assignFirstChildViewController:childViewController];
    }else{

        [self.currentChildViewController willMoveToParentViewController:nil];
        [self addChildViewController:childViewController];

        __weak __block PTSBaseContainerViewController *weakSelf=self;
        [self transitionFromViewController:self.currentChildViewController
                          toViewController:childViewController
                                  duration:1.0
                                   options:0
                                animations:^{
                                    [UIView transitionFromView:self.currentChildViewController.view toView:childViewController.view duration:1.0 options:UIViewAnimationOptionTransitionCrossDissolve completion:NULL];
                                }
                                completion:^(BOOL finished) {
                                    [weakSelf.currentChildViewController removeFromParentViewController];
                                    weakSelf.currentChildViewController = childViewController;
                                    [weakSelf.currentChildViewController didMoveToParentViewController:weakSelf];
                                }];


    }
}

The problem is that the view of the child view controller is added in portrait orientation and it messes up the views as shown in the following image:

enter image description here

The green view is the view of the child view controller which as you can see is added in portrait mode. Instead of occupying the whole yellow view (which is the container view and it occupies the whole frame of the view controller beneath the grey top bar) it is being added in portrait mode and I cannot figure it why.

PS: I tried overriding shouldAutomaticallyForwardRotationMethods and shouldAutomaticallyForwardAppearanceMethods as written in the apple documentation but with no results.

Was it helpful?

Solution

As you'll see in Apple's documentation, you need to manually set the frame for the child view controller.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top