如何设置canBecomeKeyWindow? [英] How to set canBecomeKeyWindow?
问题描述
我使用以下命令删除了窗口的标题栏:
I have removed the title bar of a window with:
self.window?.styleMask = NSBorderlessWindowMask
self.window?.movableByWindowBackground = true
Now the text fields are not working and are disabled because without title bar canBecomeKeyWindow
is set to false
, as specified in the official documentation.
我尝试过:
self.window?.makeKeyWindow()
但是它不起作用.如何将其设置为true?
But it is not working. How I can set it to true?
推荐答案
如果变量是只读的(即 {get}
,而不是 {get set}
),您无法设置它( ... = ...
),只能读取它.为了确保它在返回值时返回您想要的值,您需要对相关类进行子类化,重写相关属性,然后返回该值:
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
}
}
这篇关于如何设置canBecomeKeyWindow?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!