xcode 显示后调整 NSPopover 的大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14449945/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Resize NSPopover after it is shown
提问by Chris
I have an NSPopover who's content in an NSView. I create the popover and add the view like this:
我有一个 NSPopover,它包含在 NSView 中的内容。我创建弹出窗口并添加这样的视图:
NSPopover *thePopover = [[NSPopover alloc] init];
[thePopover setContentViewController:myViewController];
I then show the popover and set the size:
然后我显示弹出窗口并设置大小:
[thePopover setContentSize:NSMakeSize(300.0f, 160.0f)];
At this point the popover is visible and its content view is correct. Is there a way that I can resize the popover at this point without closing and re-showing it?
此时,popover 是可见的,其内容视图是正确的。有没有一种方法可以在此时调整弹出框的大小而无需关闭并重新显示它?
回答by Chris
I was able to achieve this by calling back to the controller that launched the popover via a delegate protocol and resetting the size using the setContentSize:
我能够通过回调通过委托协议启动弹出框的控制器并使用 setContentSize:
回答by Peter Hosey
From the documentation:
从文档:
The popover's content size is set to match the size of the content view when the content view controller is set.
当设置内容视图控制器时,弹出窗口的内容大小设置为匹配内容视图的大小。
So, set the frameof the popover's content view.
回答by Valentin Shergin
NSWindow
has private property _popover
that store a reference to NSPopover
.
You can use it to access to NSPopover
instance from any NSViewController
(and then call setContentSize:
on it) like this:
NSWindow
具有_popover
存储对 的引用的私有属性NSPopover
。您可以使用它NSPopover
从任何NSViewController
(然后调用setContentSize:
它)访问实例,如下所示:
- (NSPopover *)popover
{
NSWindow *window = self.view.window;
NSPopover *popover = [window valueForKey:@"_popover"];
return popover;
}