makeFirstResponder:并不总是带光标
问题描述:
当我用键盘快捷方式显示我的应用程序或通过点击状态栏中的图标时,我设置了第一响应者。 makeFirstResponder:
总是成功(返回true
),非零窗口和非零NSTextField
。然而,它并不总是“取光标”(即将闪动移动到NSTextField
)。makeFirstResponder:并不总是带光标
例如,
- 显示应用程序 - 再次
- 显示应用程序以外的应用程序需要光标✓
- 抽头 - 不采取光标(即使
makeFirstResponder
返回true
)。
以下是我正在努力做到这一点:
//Find the key window. I don't think this is the problem because self.window produces the same results.
var keyWindow:NSWindow = popover.contentViewController!.view.window!
for window in NSApplication.sharedApplication().windows{
if (window.keyWindow){
Swift.print("window \(window) is the key window")
keyWindow = window
}
}
//iFR is a variable that I use to keep track of which NSTextField I want to focus on. It's always a valid textField and most of the time (but not always) it's the only NSTextField in the view.
if (initialFirstResponder != nil)
{
if keyWindow.makeFirstResponder(initialFirstResponder)
{
Swift.print("first responder success")
}else
{
//Never happens:
Swift.print("first responder FAIL")
}
}else
{
Swift.print("no initial firstResponder")
}
答
我觉得我桥段响应链就范,但
NSApp.activateIgnoringOtherApps(true)
使光标总是抓住(并很好地问)去我想要的地方。