Search code examples
iosobjective-cuiviewcontrollercontainerschildviewcontroller

Why is child view controller occupies the entire screen?


I'm trying to learn how to make child view controller and face the problem: child view controller I made for some unknown reasuns occupies the whole screen instead of view to which I add it. Here is my super-simple code:

CVCChildViewController *childViewController =
    [[self storyboard] instantiateViewControllerWithIdentifier:kVCIdentifier];
[self addChildViewController:childViewController];
[self.childView addSubview:childViewController.view];
[childViewController didMoveToParentViewController:self];

And here is storyboard screen: enter image description here

White UIView (childView) is subview of self.view. And I wand child view controller does not cross this childView bounds. How could I do this?


Solution

  • enter image description here

    Here was my problem. "Resize View From NIB" should be unchecked for child view controller. After that it will be with correct frame. That's because this option make viewController.view.frame equal to applicationFrame by default.