Who is responsible for calling viewWillLayoutSubviews () / viewDidLayoutSubviews () in a custom UIViewController container?

When creating a custom container UIViewController

(a UIViewController

that contains other UIViewControllers and their views), who is responsible for calling viewWillLayoutSubviews and viewDidLayoutSubviews ? There are two subcontrollers in my container class, of which none of these methods are called when it moves to the parent view controller.

The UIViewController beginAppearanceTransition (_: animated :) documented as the correct way to start viewWillAppear()

, viewWillDisappear()

, viewDidAppear()

, and viewDidDisappear()

, but I see no equivalent to viewWillLayoutSubviews()

/ viewDidLayoutSubviews()

.

At best, I can define a parent view controller (which in this case is exposed via presentViewController (_: animated: completion :) ) is responsible for calling its subcontrollers viewWillLayoutSubviews()

/ viewDidLayoutSubviews()

in its implementation of the same methods. The framework appears to call these methods under certain circumstances (like when you set a property rootViewController

UIWindow

) but not others (like when you call addChildViewController()

in UIViewController

).

Is this the correct, idiomatic way to do things?

+3


source to share


2 answers


Who is responsible for calling viewWillLayoutSubviews and viewDidLayoutSubviews?



Lead time. You should never call these methods yourself.

+3


source


According to the docs viewWillLayoutSubviews :



When a rotation occurs for a visible view controller, the willRotate (to: duration :), willAnimateRotation (to: duration :), and didRotate (from :) methods are called. The viewWillLayoutSubviews () method is also called after the view has been resized and positioned by its parent. If the view controller is not visible when the orientation change occurs, then the rotation methods are never called. However, the viewWillLayoutSubviews () method is called when the view becomes visible. Your implementation of this method can call the statusBarOrientation method to determine the orientation of the device.

0


source







All Articles