I have a custom view that's not getting layoutSubview
messages during animation.
I have a view that fills the screen. It has a custom subview at the bottom of the screen that correctly resizes in Interface Builder if I change the height of the nav bar. 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.
Under what circumstances is layoutSubviews
actually called?
I have autoresizesSubviews
set to NO
for my custom view. And in Interface Builder I have the top and bottom struts and the vertical arrow set.
Another part of the puzzle is that the window must be made key:
[window makeKeyAndVisible];
of else the subviews are not automatically resized.
I tracked the solution down to Interface Builder's insistence that springs cannot be changed on a view that has the simulated screen elements turned on (status bar, etc.). Since the springs were off for the main view, that view could not change size and hence was scrolled down in its entirety when the in-call bar appeared.
Turning the simulated features off, then resizing the view and setting the springs correctly caused the animation to occur and my method to be called.
An extra problem in debugging this is that the simulator quits the app when the in-call status is toggled via the menu. Quit app = no debugger.
have you looked at layoutIfNeeded?
The documentation snippet is below. Does the animation work if you call this method explicitly during the animation?
layoutIfNeeded Lays out the subviews if needed.
Discussion Use this method to force the layout of subviews before drawing.
Availability Available in iPhone OS 2.0 and later.
I had a similar question, but wasn't satisfied with the answer (or any I could find on the net), so I tried it in practice and here is what I got:
init
does not causelayoutSubviews
to be called (duh)addSubview:
causeslayoutSubviews
to be called on the view being added, the view it’s being added to (target view), and all the subviews of the targetsetFrame
intelligently callslayoutSubviews
on the view having its frame set only if the size parameter of the frame is differentlayoutSubviews
to be called on the scrollView, and its superviewlayoutSubview
on the parent view (the responding viewControllers primary view)layoutSubviews
on its superviewMy results - http://blog.logichigh.com/2011/03/16/when-does-layoutsubviews-get-called/