Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto Layout = ViewWillAppear has the wrong width of the view

Tags:

ios

autolayout

I am using autolayout for parts of my UI. When I check the width of my view in viewWillAppear, the width has not yet updated. It gets updated after the second callback to - (void)updateViewConstraints. The issue is I set up my parts of my UI (using spring and struts for legacy reasons) based on this width in viewWillAppear. When is the good time to set up this legacy UI which takes in a width parameter ?

thanks

like image 534
FatalError Avatar asked Feb 17 '15 02:02

FatalError


1 Answers

Layout happens after viewWillAppear returns. Do it in viewDidLayoutSubviews (in your view controller) or in layoutSubviews (in your custom view subclass). Either way, be sure to call super first.

Another way is to force layout by sending [view layoutIfNeeded]. Then you can add subviews and set their springs and struts. The system will perform layout again (at its usual time) because you added subviews.

like image 72
rob mayoff Avatar answered Oct 19 '22 03:10

rob mayoff