Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: determine when all children have had layoutSubviews called

it appears that viewDidLayoutSubviews is called immediately after layoutSubviews is called on a view, before layoutSubviews is called on the subviews of that view. Is there any way of knowing when layoutSubviews has been called on a view and all of its children that also needed their layouts updated?

like image 803
Thayne Avatar asked Dec 24 '13 19:12

Thayne


People also ask

How many times is layoutSubviews called?

layoutSubviews is called when the view is created, but never again. My subviews are correctly laid out. If I toggle the in-call status bar off, the subview's layoutSubviews is not called at all, even though the main view does animate its resize.

What triggers layoutSubviews?

The least expensive way to trigger a layoutSubviews call is calling setNeedsLayout on your view. This will indicate to the system that the view's layout needs to be recalculated. setNeedsLayout executes and returns immediately and does not actually update views before returning.

When can I call super layoutSubviews?

For more recent versions of iOS, you should call [super layoutSubviews] at the beginning of your implementation. Otherwise, the superclass will rearrange your subviews after you do the custom layout, effectively ignoring your implementation of layoutSubviews() .

What is setNeedsLayout?

Invalidates the current layout of the receiver and triggers a layout update during the next update cycle.


1 Answers

You shouldn't have to know if the subviews of a subview have updated their layout: That sounds like too tight coupling. Also, each subview might handle the arrangement of their respective subviews differently and might not (need to) call layoutSubviews for its subviews at all. You should only ever have to know about your direct subviews. You should treat them more or less as black boxes and not care whether they have subviews of their own or not.

like image 156
Johannes Fahrenkrug Avatar answered Oct 13 '22 13:10

Johannes Fahrenkrug