调整nspopover的大小 [英] Resizing nspopover

查看:199
本文介绍了调整nspopover的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试显示NSPopover的大小之前,我试图通过使用以下方法设置它包含的NSView的框架来调整其大小:

I am trying to resize an NSPopover prior to displaying it by setting the frame of the NSView it contains using the method:

setFrameSize:

但是,当我尝试通过调用显示弹出窗口时:

However, when I try to display the popover by calling:

showRelativeToRect: ofView: preferredEdge:

该视图返回其先前的大小.为什么会这样呢?我应该用另一种方式调整弹出窗口的大小吗?

The view returns to its previous size. Why is this happening? Is there another way I should be sizing the popover?

Ben,谢谢.

推荐答案

弹出框上有一个setContentSize,但我有一个印象,那就是效果不佳.我的意思是它可以工作,但是会调整内容的大小(包括子视图).因此,更好的方法是创建一个新的NSViewController并为其分配新视图.在NSPopover上设置此新控制器时,会适当考虑其大小,如果当前显示该弹出框,它将为新视图设置动画.

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;

这篇关于调整nspopover的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆