Resizing nspopover

匆匆过客 提交于 2019-12-07 00:49:34

There's a setContentSize on the popover, but I have the impression this doesn't work so well. I mean it works, but resizes the content (including child views). So the better way is to create a new NSViewController and assign it the new view. On setting this new controller on the NSPopover the size is properly respected and if the popover is currently shown it will animate to the new view.

If you can't do this but instead want to resize the content in place use something like this:

NSRect frame = valuePopupList.frame;
frame.origin = NSMakePoint(2, 2);

... determine new frame ...

NSSize contentSize = frame.size;
contentSize.width += 4; // Border left/right.
contentSize.height += 4; // Ditto for top/bottom.
if (contentSize.height < 26) {
    contentSize.height = 26;
}
valuePopupList.frame = frame;
statementsPopover.contentSize = contentSize;

[statementsPopover showRelativeToRect: area ofView: view preferredEdge: NSMaxXEdge];
valuePopupList.frameOrigin = frame.origin;

You should implement -preferredContentSize in your NSViewController that is contained by the popover. That seems to be the most reliable way of controlling the popover size.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!