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?
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.
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.
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() .
Invalidates the current layout of the receiver and triggers a layout update during the next update cycle.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With