【问题标题】:Resizing nspopover调整 nspopover 的大小
【发布时间】:2013-01-17 12:18:20
【问题描述】:

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

setFrameSize:

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

showRelativeToRect: ofView: preferredEdge:

视图恢复到之前的大小。为什么会这样?还有其他方法可以调整弹出框的大小吗?

提前致谢,本。

【问题讨论】:

    标签: resize nsview nspopover


    【解决方案1】:

    弹出框上有一个 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;
    

    【讨论】:

      【解决方案2】:

      您应该在弹出框包含的 NSViewController 中实现 -preferredContentSize。这似乎是控制弹出框大小的最可靠方法。

      【讨论】:

        猜你喜欢
        • 2021-09-17
        • 2018-06-23
        • 2015-10-26
        • 2013-01-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多