I have been mainly working with storyboard until I recently moving to only creating controller with code.
I followed our coding standard to create some subview in the loadView()
function, inside which, the first line is super.loadView()
.
From what I observed, after I called super.loadView()
, the frame of self.view
is already set correctly with the viewController itself, which is exactly the frame of the viewController.
My more experience colleagues are saying this was 100% not working in the old days that it should give u CGRectZero
instead and probably I should not rely on it.
I want to hear more suggestion from other people.
Here is my sample project setup:
1. create a simple proj
2. add a button in the first VC
3. create second VC by code, override loadView()
function in second VC, call super.loadView()
there and print self.view.bounds
next line
4. self.present
or use navigation controller from VC1 in the button action to present or push to VC2
5. it always give me correct frame of the second VC.
Please let me know.
----------- Edit -------------
To clarify my question, I know the lifecycle functions like viewDidLayoutSubviews
or layoutSubViews
to return the correct view. I am NOT asking these.
My question is why loadView()
IS returning me the CORRECT frame now.