How to set canBecomeKeyWindow?

余生颓废 提交于 2021-01-28 05:06:56

问题


This may be very trivial question but I am not able to figure it out. I have removed titlebar of a window by-

self.window?.styleMask = NSBorderlessWindowMask
self.window?.movableByWindowBackground = true

Now Any textfield is not working and are disabled because without title bar canBecomeKeyWindow is set to false. Please refer This

How I can set it to true?

I have tried

self.window?.makeKeyWindow()

But it is not working. Thanks for your help.


回答1:


If a variable is read-only (i.e. { get }, rather than { get set }) you can't set it (... = ...), you can only read it. To make sure it's returning the value you want when you do read it, you need to subclass the class in question, override the relevant property, and return that value:

class PPWindow: NSWindow {

    override var canBecomeKeyWindow: Bool {
        return true
    }
}


来源:https://stackoverflow.com/questions/30776875/how-to-set-canbecomekeywindow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!