viewWillTransition before viewDidLoad

When launching an app in landscape, viewWillTransition(to:with:) is called before viewDidLoad(). Is this normal?

Replies

Yes. From the documentation:

"View controllers load their views lazily. Accessing the

view
property for the first time loads or creates the view controller’s views."


This means that the code in your view controller can get instantiated into memory (and 'init' called) and hooked up to everything (e.g. the rortation of the device) before accessing the view itself. Then at some point the view is accessed. For example, if the view controller is referenced by a tabController then when the tabController is initiated so is the view controller - but not the view. The view will be accessed only if its tab is tapped. Only then will viewDidLoad get called.

Docs say this about viewWillTransition:


'UIKit calls this method before changing the size of a presented view controller’s view.' - In which case I'd assume yes, before, and yes, normal, just remember that not all devices support launching in landscape, so, normal when applies.


However, when an app is launched in landscape, there is no transition. The UI is already there. Perhaps you intended another scenario...