makeFirstResponder:并不总是带光标
makeFirstResponder: does not always take cursor
当我使用键盘快捷键或点击状态栏中的图标显示我的应用程序时,我设置了第一响应者。 makeFirstResponder:
总是成功 (returns true
) 并且有一个非零 window 和一个非零 NSTextField
。然而,它并不总是 'take the cursor'(即将闪烁的 | 移动到 NSTextField
)。
例如,
- 显示应用 - 获取光标 ✓
- 点击应用程序外部
- 再次显示应用程序 - 不带光标(即使
makeFirstResponder
returns 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)
使光标始终被捕获(并被很好地询问)到我想要的位置。
当我使用键盘快捷键或点击状态栏中的图标显示我的应用程序时,我设置了第一响应者。 makeFirstResponder:
总是成功 (returns true
) 并且有一个非零 window 和一个非零 NSTextField
。然而,它并不总是 'take the cursor'(即将闪烁的 | 移动到 NSTextField
)。
例如,
- 显示应用 - 获取光标 ✓
- 点击应用程序外部
- 再次显示应用程序 - 不带光标(即使
makeFirstResponder
returnstrue
)。
以下是我尝试执行此操作的方法:
//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)
使光标始终被捕获(并被很好地询问)到我想要的位置。