Auto Layout = ViewWillAppear has incorrect view width

I use autorun for parts of my interface. When I check the width of my view in viewWillAppear, the width is not yet updated. It is updated after the second callback - (void) updateViewConstraints. The problem is that I created my parts of my user interface (using spring and struts for legacy reasons) based on this width in viewWillAppear. When is the best time to install this legacy user interface that accepts a width parameter?

thanks

+5
source share
1 answer

Layout happens after viewWillAppear . Do this in viewDidLayoutSubviews (in your view controller) or in layoutSubviews (in your custom view subclass). In any case, first call super first.

Another way is to format the layout by sending [view layoutIfNeeded] . Then you can add subviews and set their springs and struts. The system will execute the layout again (at normal times) because you added subviews.

+12
source

Source: https://habr.com/ru/post/1213501/


All Articles