I am using containerView. Many things are strange about the containerView.
One of the strange thing is that the type of the view is just UIView. So, what's the different between this view and all the other subViews out there?
Then I started setting things up after reading a bunch of sample code.
[self.ContainerView addSubview:self.listBusinessViewController.view];// initialize'
At that time, self.listBusinessViewController is already a child of the self. So self have 3 children.
What's surprising is the the frame size of the self.listBusinessViewController.view remain the way I set that up in the xib rather than automatically resized to the ContainerView.
If I do this:
[self.ContainerView addSubview:self.listBusinessViewController.view];// initialize'
PO(NSStringFromCGRect(self.ContainerView.frame));
PO(NSStringFromCGRect(self.listBusinessViewController.view.frame));
PD(self.listBusinessViewController.view.autoresizingMask);
PD(UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight);
I got:
NSStringFromCGRect(self.ContainerView.frame): {{0, 48}, {320, 412}}
NSStringFromCGRect(self.listBusinessViewController.view.frame): {{0, 0}, {320, 480}}
self.listBusinessViewController.view.autoresizingMask: 18
UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight: 18
so, ContainerView has a height of 412 The listBusinessViewController.view has a height of 480 The autoresizingMask is 18, which is expected. It means that it has flexible width, height, and inflexible border.
So why the listBusinessViewController.view's height doesn't become 412, like it's superview?
I can, of course, do this the high handed way using
CGRect frameOfAllChild = CGRectMake(0, 0, self.ContainerView.frame.size.width, self.ContainerView.frame.size.height);
for (UIViewController * child in self.childViewControllers) {
child.view.frame=frameOfAllChild;
}
Code ubber alles (at least ubber xib). However, the whole point of having flexible height and width is so that the view fill out it's superview or it's windows.
Am I missing something?
Adding a view to a superview does not change the frame of the added view. A view will only resize its subviews if it is resized whilst the subviews are present.
In storyboards, the container view can be used with an embed segue to directly add the content of another view controller. Here the contained view controller is laid out in a frame matching the size. In xibs (where I haven't used them, I must confess) they are not much more than placeholders to aid with layout. You would need to resize the frame of your child view controller's view before adding it. After that, resizing the container will resize the subviews.
Your final code snippet is better written as
child.view.frame = self.ContainerView.bounds;