ViewDidLayoutSubviews, viewdidload
For various reasons, we have recently started to use autolayout in a new project. Although it is smooth, it has encountered some troubles, such:
The default XIB screen I use is a 4-inch screen. I add a viewA IN THE XIB, with a width of 320 and a ceiling of the SuperView width.
Then I used a 4-inch simulator and run the Code. In ViewDidload, I took out the viewA width and found that the width of the SuperView (self. view) is 320.
The result is correct.
However, I used a 5.5-inch simulator to run the code. When ViewDidLoad is used to retrieve the viewA width, it is found that it is still 320, And the SuperView (self. view) width is also 320.
This is incorrect.
This causes some controls to be initialized in ViewDidLoad, so that the frame size of these controls is the default size of XIB, rather than the expected size after the constraint is added.
I have been entangled in this problem for a long time, Baidu Google for a long time, and I do not know whether the keyword is correct or why, seeking for fruitless results, and finally asking a great God to be enlightened.
Originally, there was another life cycle function from iOS5.0.ViewDidLayoutSubViewsThis method can basically replace ViewDidload, but the difference is that the former is a constraint, and the latter is a constraint.
When smart readers think of Did, there Will be Will, that isViewWillLayoutSubViews.
I hope this article will help you!