【问题标题】:Adjusting size of popup window调整弹出窗口的大小
【发布时间】:2019-10-22 09:50:26
【问题描述】:

我想构建一个模式对话框窗口,其中包含许多 NSView,在编译时不知道要显示多少视图。我已经能够用视图填充一个窗口,但有两个问题阻碍了我。一种是根据要显示的项目数量来调整窗口的大小。另一个帖子将解决另一个问题。

我使用情节提要创建一个带有“确定”和“取消”按钮的窗口,然后添加到窗口的内容中

以下是我的代码的基本部分:

class ParmViewController: NSViewController {

    static func showParmDialog()
    {
        let storyboard = NSStoryboard(name: "Main", bundle: nil)
        let windowController = storyboard.instantiateController(withIdentifier: "ParmViewController") as! NSWindowController
        let window = windowController.window!
        let viewController = window.contentViewController as! ParmViewController
        viewController.setup()
        let application = NSApplication.shared
        application.runModal(for: window)
        window.close()
    }
    let newHeight:CGFloat = 240        
    func setup() {
        print( view.frame )        // prints (0.0, 0.0, 300.0, 180.0)
        view.frame = NSRect( x: 0, y: 0, width: 300, height: newHeight )
        print( view.frame )        // prints (0.0, 0.0, 300.0, 240.0)
    }
}

上面的代码对窗口的显示大小没有影响。视图有一个超级视图,它比这个窗口高 22 像素——调整它的大小也没有效果。

如何调整屏幕上的窗口大小?

【问题讨论】:

    标签: swift macos nsviewcontroller


    【解决方案1】:

    如果我将代码移动到viewDidLoad(),则调整大小有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-20
      • 2016-03-28
      • 1970-01-01
      相关资源
      最近更新 更多