剪切/复制/粘贴键盘快捷键在NSPopover中不起作用 [英] Cut/copy/paste keyboard shortcuts not working in NSPopover

查看:107
本文介绍了剪切/复制/粘贴键盘快捷键在NSPopover中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于macOS NSPopover的任务栏应用程序,其中显示了一个带有登录字段(用户名和密码)的弹出式窗口.

I have a macOS NSPopover based tray app which shows a popover with login fields (username and password).

问题是用户无法将其电子邮件或密码复制粘贴到文本字段中.由于某些原因,弹出窗口似乎不允许键盘快捷键.

Problem is that user is unable to copy-paste his email or password into text fields. The popover doesn't seem to allow keyboard shortcuts for some reason.

有人有类似的问题吗?

此处提供了相关示例: https://github.com/mixtly87/NSPopoverTest

Relevant example available here: https://github.com/mixtly87/NSPopoverTest

推荐答案

这不是最容易解决的问题,您需要做一些事情才能使它起作用.

This isn't the easiest thing to solve and you need to do a few things to get this to work.

1)将MainMenu添加到MainMenu.xib文件.

1 ) add a MainMenu to your MainMenu.xib file.

即使主菜单不会显示(因为您仅在执行NSStatusBar项),您还是希望该主菜单是由于编辑"菜单中的命令键(例如,用于拦截 cmd的东西 -X, cmd -C和 cmd -V).无论第一响应者是谁,这些命令键都会发送到您的文本字段或Web视图.

Even though the main menu won't display (because you're only doing a NSStatusBar item), you want that main menu because of the command keys in the Edit menu (i.e. something to intercept the cmd-X, cmd-C & cmd-V's). Those command keys will be sent to your text field or your webview, whatever is the first responder.

可在此处查看更多信息.

2)

我通过添加以下内容使您的文本字段成为第一响应者:

I made your textfield the first responder by adding:

- (void)viewDidAppear
{
    [super viewDidAppear];
    [self.textField becomeFirstResponder];
}

到您的ViewController.m文件.

to your ViewController.m file.

3)

您还需要将状态项"弹出的窗口设置为关键窗口.在示例应用程序中,确实有一个注释掉的canBecomeKeyWindow方法.我取消注释并始终返回TRUE.

You also need to make the window brought up by the Status Item a key window. In your example app, you did have a commented out canBecomeKeyWindow method. I uncommented it out and always return TRUE.

更多信息可以在这里看到.

希望这会有所帮助!

这篇关于剪切/复制/粘贴键盘快捷键在NSPopover中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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