我正在尝试在显示NSPopover之前调整它的大小,方法是使用以下方法设置它所包含的NSView的框架:
setFrameSize:但是,当我尝试通过调用以下命令来显示弹出窗口时:
showRelativeToRect: ofView: preferredEdge:视图将恢复到以前的大小。为什么会发生这种情况?有没有其他方法可以调整popover的大小?
先谢谢你,本。
发布于 2013-04-23 01:40:36
popover上有一个setContentSize,但我觉得这个效果不太好。我的意思是它可以工作,但会调整内容(包括子视图)的大小。因此,更好的方法是创建一个新的NSViewController并为其分配新的视图。在NSPopover上设置这个新控制器时,大小得到了适当的考虑,如果当前显示了弹出窗口,它将动画显示到新视图中。
如果您不能做到这一点,但是想要适当地调整内容的大小,请使用如下所示的内容:
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;发布于 2019-02-21 07:46:40
您应该在popover包含的NSViewController中实现-preferredContentSize。这似乎是控制popover大小的最可靠方法。
https://stackoverflow.com/questions/14378949
复制相似问题