Hi,
I have been using Autolayout and size classes for a while, but I still seem to get confuse with how viewWillTransitionToSize: and sizeForChildContentContainer: work when used in custom container controllers and in container views with Interface Builder.
My specific question is: how do you calculate a child controller size defined with constraints? (for -sizeForChildContentContainer:withParentContentSize: ) moreover when -viewWillTransitionToSize: run before the constraint and layout cycle.
By default viewWillTransitionToSize:withTransitionCoordinator seems to perform the following (more things seems to be going on with presentedViewControllers, but it is not important for the matter at hand).
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coord
{
for (UIViewController* child in self.childViewControllers
{
CGSize const childSize = [self sizeForChildContentContainer:child withParentContentSize:size];
[child viewWillTransitionToSize:childSize withTransitionCoordinator:coord];
}
}If you don't override -sizeForChildContentContainer:withParentContentSize:, the method will simple return what you pasted as the parent content size. Meaning that the childVCs will have the same size as the parentVC. That is wrong for most cases, and that is why one should override -sizeForChildContentContainer: and calculate the proper size. However -viewWillTransitionToSize: will run before the updateConstraint and layout cycle (marked subtely by the "will" prefix of the method name).
So, if you define the position of your childVCs or containerVCs with constraints (whether in Interface Builder or by code). There seems to be no way to pass the proper size down the chain of -viewWillTransitionToSize:withTransitionCoordinator:
Am I missing something?
Thanks beforehand.