全屏按钮已禁用

时间:2018-06-14 13:22:09

标签: swift macos cocoa

我是Cocoa Apps开发的新手。由于某些未知原因,我的fullscreen按钮被禁用。可能问题出在styleMask。这是我的代码:

class AppDelegate: NSObject, NSApplicationDelegate {
    lazy var window = NSWindow(contentRect:
        NSRect(center: NSScreen.main?.frame.center ?? .zero, size: CGSize(width: 800, height: 450)),
                               styleMask: [.titled, .miniaturizable, .closable, .fullSizeContentView],
                               backing: NSWindow.BackingStoreType.buffered,
                               defer: false)

    func applicationDidFinishLaunching(_ aNotification: Notification) {
        let vc = Router.getPhotoBrowserNSViewController()
        window.contentViewController = vc
        window.delegate = NSWindowHandler()
        window.titlebarAppearsTransparent = true
        window.isMovableByWindowBackground  = true
        window.makeKeyAndOrderFront(nil)
        window.maxFullScreenContentSize = NSScreen.main?.frame.size ?? .zero
        window.minFullScreenContentSize = CGSize(width: 800, height: 450)
    }
}

结果如下: https://imgur.com/NE4fgfG

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:2)

您需要将窗口collectionBehavior设置为包含.fullScreenPrimary的选项集。