ViewDidLayoutSubviews, viewdidload

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.