辅助监视器上的全屏NSWindow-Swift [英] Fullscreen NSWindow on Secondary Monitor - Swift

查看:174
本文介绍了辅助监视器上的全屏NSWindow-Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Obj C上看到了很多关于此的帖子.很快就看不到太多了,我只是无法使它工作.我希望能够在特定的NSScreen上全屏显示窗口. "ToggleFullscreen"方法不是最好的方法,因为没有太多选项(用于外部显示).我尝试过:

I have seen many posts on this in Obj C. Not too many in swift, and I just can't get it to work. I want to be able to make a window fullscreen on a specific NSScreen. The 'ToggleFullscreen' method isn't the best way because there aren't many options (for external displays). I tried:

    // screen is my variable already set
    outputWindow!.window!.setFrame(screen.frame, display: true, animate: true)
    outputWindow!.window!.styleMask = NSFullScreenWindowMask
    outputWindow!.window!.level = Int(CGShieldingWindowLevel())

    // the above one doesn't make it fullscreen.
    // it has a title bar and shows the menu on the screen. 



    // then i tried....
    fullscreenWindow = NSWindow(contentRect: screen.frame, styleMask:NSBorderlessWindowMask, backing: NSBackingStoreType.Buffered, defer: false, screen: screen)
    fullscreenWindow.level = Int(CGShieldingWindowLevel())
    fullscreenWindow.makeKeyAndOrderFront(nil)

    //that one works on my main display (somewhat). and does nothing on externals. 

我注意到,制作自己的全屏电影的一件事就是卡住了它.这不像OS X的全屏模式,您可以按esc键将其退出.有什么窍门吗?谢谢

One thing I noticed with making my own fullscreen is that I get stuck into it. It's not like the OS X fullscreen where you can press esc to escape it. Are there any tricks to this? Thanks

推荐答案

我也很努力地陷入全屏状态.使用NSBorderlessWindowMask的原因在于,无论向其发送makeKeyAndOrderFront:还是makeKeyWindow消息,该窗口都无法成为窗口的键.在Objective-C中,解决方案是在NSWindow子类中实现canBecomeKeyWindow.

I struggled with getting stuck on fullscreen as well. The reason behind that is using NSBorderlessWindowMask prevents the window from becoming key regardless of sending the makeKeyAndOrderFront: or makeKeyWindow messages to it. In Objective-C, the solution was to implement canBecomeKeyWindow in the subclassed NSWindow.

- (BOOL)canBecomeKeyWindow {
     return YES;
}

现在,它也将在全屏显示后接收关键事件.

Now it receives key events after going full screen as well.

这篇关于辅助监视器上的全屏NSWindow-Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆