我试图在第二个屏幕上使用第二个窗口全屏显示,我仍然看到菜单栏。
这是我的代码:
let second_screen = NSScreen.screens()?[1]
let window = NSWindow(contentRect: (second_screen?.frame)!, styleMask: .fullScreen, backing: .buffered, defer: true, screen: second_screen)
self.window_controller = NSWindowController(window: window)
window.collectionBehavior = .fullScreenAuxiliary
window_controller?.showWindow(self)
window.toggleFullScreen(true)
有没有人对此有任何好运?
修改1:
我添加了这一行:
NSApp.presentationOptions = [.fullScreen, .hideDock, .autoHideMenuBar]
我收到了这个警告:
setPresentationOptions called with NSApplicationPresentationFullScreen when there is no visible fullscreen window; this call will be ignored.
编辑2:
我切换到这个方法:
let presOptions: NSApplicationPresentationOptions = [.hideDock, .hideMenuBar]
let optionsDictionary = [NSFullScreenModeApplicationPresentationOptions: NSNumber(value: presOptions.rawValue)]
self.fullscreen_view?.enterFullScreenMode((NSScreen.screens()?[1])!, withOptions: optionsDictionary)
视图全屏显示内容,只显示灰色。
编辑3:
我关闭了NSFullScreenModeAllScreens,现在它有点工作:
let optionsDictionary = [NSFullScreenModeApplicationPresentationOptions: NSNumber(value: presOptions.rawValue), NSFullScreenModeAllScreens: false]
现在唯一的事情是菜单栏和停靠栏不会显示在第一个屏幕上。
答案 0 :(得分:0)
对我来说,enterFullScreenMode
似乎只能在视图“已显示”之后调用才能正常工作。
如果我在func applicationDidBecomeActive(_ notification: Notification) { /* here */ }
内部调用它(或者也可以通过使用Timer.scheduledTimer
),它就会起作用。