Apple says:
"Container view controllers use this method to return the sizes for their child view controllers. UIKit calls the method as part of the default implementation of the viewWillTransition(to:with:) method for view controllers"
And when i first time launch program:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let child = ViewControllerChild()
self.addChildViewController(child)
self.view.addSubview(child.view)
child.view.translatesAutoresizingMaskIntoConstraints = true
child.view.autoresizingMask = [.flexibleBottomMargin, .flexibleRightMargin]
}
override func size(forChildContentContainer container: UIContentContainer, withParentContainerSize parentSize: CGSize) -> CGSize {
return CGSize(width: 100, height: 100)
}
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
}
} I get full parent vc view's size child view controller's view not (100, 100). So what the real point to override it, if i can respond to trait changes by redefining child vc view's frame in (1st load in viewdidload) then in preferredContentSizeDidChange function?
From the notes you put in the question :
Question: Are you sure that overridden methods are being invoked?
What's missing?
Docs : https://developer.apple.com/documentation/uikit/uiviewcontroller/1621405-didmovetoparentviewcontroller