【问题标题】:How to open a windowcontroller on top of a maximised windowcontroller如何在最大化的窗口控制器之上打开一个窗口控制器
【发布时间】:2018-09-26 15:45:24
【问题描述】:

我有一个带有 mainwindowController 的 osx (MacOS) 应用程序,用户可以最大化视图。该应用程序还有一个作为子窗口控制器打开的首选项窗口。

但是,如果主窗口最大化,子窗口也会尝试最大化,最终会出现黑屏,子窗口显示在中间。

有没有办法让子窗口根据主窗口最大化状态不显示,子窗口总是不最大化。

这里是首选项窗口如何显示的一些代码。

let currentWindowController = self.view.window?.windowController as! MainWindowViewController
            let childWindowControllers = windowControllers[currentWindowController]
            if let subPreferencesWindowController: SubPreferenceWindowViewController? = {
                for windowController in childWindowControllers! {
                    if windowController is SubPreferenceWindowViewController {
                        return windowController as? SubPreferenceWindowViewController
                    }
                }
                return nil
            }(){
                let subPreferencesController = subPreferencesWindowController?.contentViewController as! SubPreferenceViewController
                subPreferencesController.appStateJSON = self.appStateJSON!
                subPreferencesController.preferences = self.preferencesJSON!
                subPreferencesController.setUpSubPreferences()
            }

【问题讨论】:

  • 是最大化全屏还是缩放?
  • 全屏。用户点击了窗口展开按钮
  • 将窗口的collectionBehavior设置为[.canJoinAllSpaces, .fullScreenAuxiliary]

标签: swift macos nsviewcontroller nswindowcontroller


【解决方案1】:

已解决 - 当我创建窗口时,我添加了一个样式掩码以将新窗口设置为不可调整大小。 (最后一行代码)

if let subPreferenceViewController = storyboard.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier(rawValue: "sub-preferences")) as? SubPreferenceViewController {
            let subPreferenceWindow = NSWindow(contentViewController: subPreferenceViewController)
            let subPreferenceWindowController = SubPreferenceWindowViewController(window: subPreferenceWindow)
            var windowControllersForCurrent =  windowControllers[currentWindowController]
            windowControllersForCurrent?.append(subPreferenceWindowController)
            windowControllers[currentWindowController] = windowControllersForCurrent
            newWindowController = subPreferenceWindowController
            newWindow = subPreferenceWindow
            newWindow.standardWindowButton(.zoomButton)!.isHidden = true
            width = 400
            height = 607
            newWindow.maxSize = NSSize(width: width, height: height)
            newWindow.styleMask.remove(.resizable)
        }

【讨论】:

    猜你喜欢
    • 2018-01-26
    • 2014-03-29
    • 2014-06-16
    • 2013-06-30
    • 1970-01-01
    • 1970-01-01
    • 2018-01-02
    • 2018-08-13
    • 2014-06-24
    相关资源
    最近更新 更多