开发者

Does NSView have anything analogous to UIView's setNeedsLayout/layoutSubviews methods?

Do I put such things into the display method? O开发者_运维知识库r is there something analogous?


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.


resizeSubviewsWithOldSize: seems like it does nothing. Never gets called at all for me. Maybe it's because I use autolayout and the documentation says it's related to autoresizing.

NSView's layout appears to be the same as UIView's layoutSubviews. They're both overridable if you want to do some special work to replace or in addition to autoresizing or autolayout.

Calling this on UIView

[view setNeedsLayout];

seems to be the same as this on NSView

view.needsLayout = YES;

Which begs the question, why is "setNeedsLayout" even a function name? Like, really, you decided to remove the parameter from a setter function, and keep the "set" in the title? Why not "scheduleLayout"? This would obviate the need for Stack Overflow questions like this.


Sometimes, resizeSubviewsWithOldSize doesn't get called. Then, try overriding resizeWithOldSuperviewSize.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜