【问题标题】:Swift OSX Fullscreen hiding status and dockSwift OSX 全屏隐藏状态和停靠
【发布时间】:2016-04-04 13:58:19
【问题描述】:

有没有办法在全屏模式下隐藏(而不是禁用)OS X 状态栏和停靠?

我有这个代码:

 func applicationDidFinishLaunching(aNotification: NSNotification) {
    /* Pick a size for the scene */
    if let scene = MainMenuScene(fileNamed:"GameScene") {

            if let screen = NSScreen.mainScreen() {

                window.setFrame(screen.frame, display: true, animate: true)
                 window.collectionBehavior = NSWindowCollectionBehavior.FullScreenPrimary

 }

NSApplicationPresentationOptions.AutoHideMenuBar
        skView.showsFPS = false
        skView.showsNodeCount = false


        skView.ignoresSiblingOrder = false

        /* Set the scale mode to scale to fit the window */
        scene.scaleMode = .AspectFill

        scene.size = skView.bounds.size
        self.skView!.presentScene(scene)
    }
}

但我得到这个错误:

  Failed to set (collectionBehavior) user defined inspected property on (NSWindow)

错在哪里?

【问题讨论】:

  • 如果在窗口出现后设置NSWindowCollectionBehavior.FullScreenPrimary呢?
  • 我尝试将 NSWindowCollectionBehavior.FullScreenPrimary 放在 MainMenuScene.swift 文件的 didmovetoview 中...但没有运气,菜单栏和停靠栏仍然可见...

标签: swift macos menu fullscreen dock


【解决方案1】:

你试过在windowController中调用self.window?.toggleFullScreen(true)吗?

例如

class WindowController: NSWindowController {

    override func windowDidLoad() {
        super.windowDidLoad()
        self.window?.toggleFullScreen(true)
    }
}

以全屏方式启动,顶部没有菜单栏,也没有停靠栏。

或者至少是something.window?.toggleFullScreen(true),其中true 应该是发件人。

【讨论】:

  • 您的第二个选项 'window?.toggleFullScreen(true)' 非常完美。首先,菜单栏和停靠栏仍然可见。
  • 这可能是因为您没有将 WindowController 的类设置为 WindowController,因此self. 参考
  • @AdrianSluyters,如何调整窗口内视图的大小?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-10
  • 2013-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多