Do I put such things into the display method? Or is there something analogous?
layoutSubviews() The system calls this method whenever it needs to recalculate the frames of views, so you should override it when you want to set frames and specify positioning and sizing. However, you should never call this explicitly when your view hierarchy requires a layout refresh.
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.
As of OSX 10.7:
- (void)layout
is equivalent to layoutSubviews
There is now an identical setNeedsLayout
.
Override this method if your custom view needs to perform custom layout not expressible using the constraint-based layout system. In this case you are responsible for calling setNeedsLayout:
when something that impacts your custom layout changes.
You may not invalidate any constraints as part of your layout phase, nor invalidate the layout of your superview or views outside of your view hierarchy. You also may not invoke a drawing pass as part of layout.
You must call [super layout]
as part of your implementation.
Analogous to layoutSubviews
is the resizeSubviewsWithOldSize:
method of NSView
. I guess, analogous to setNeedsLayout
would be calling resizeSubviewsWithOldSize:[self frame].size
directly.
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