NSMenuItem 自定义视图中可编辑的 NSTextField

发布于 2024-10-20 05:16:49 字数 326 浏览 6 评论 0原文

我有一个 NSView 子类,我想包含一个可编辑的 NSTextField,类似于 Spotlight。

我在选择和突出显示文本字段时遇到了很大的困难。如果我在文本字段的编辑区域上快速单击,我实际上可以输入文本,但它显示为灰色,就好像我正在将文本添加到不是最重要的应用程序的字段中一样。

我尝试使用 viewDidMoveToWindow 来获得视图窗口的焦点,但显然 NSMenuItem 的窗口是碳窗口,不能很好地处理按键。

长话短说,要成功完成这项工作,有什么好方法呢?我知道 Spotlight 是一个无边框窗口,但这不适合我的目的。

任何和所有建议都会非常有帮助。

I have a subclassed NSView that I would like to contain an editable NSTextField, similar to Spotlight.

I am having significant difficult getting the text field to select and highlight. If I click quickly and rapidly over the editing area of the textfield, I can actually enter text, but it appears greyed out, as though I am adding text to a field of an app that is not foremost.

I have tried to get focus of the View's window using viewDidMoveToWindow, but apparently NSMenuItem's windows are carbon windows that don't handle keys very well.

Long story short, what is a good way to go about making this work successfully? I know that Spotlight is a borderless window, but that is not suitable for my purposes.

Any and all suggestions would be very helpful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

掐死时间 2024-10-27 05:16:50

经过大量研究后,有两件事是普遍共识:

(1) 如果您发现自己正在寻找特殊方法来子类化内置 UI 元素,那么您可能做错了什么,或者至少有更好的方法做你想做的事情的方法。

(2) 遵循接口指南的原因是为了更好地兼容未来。无法保证子类 UI 元素将与操作系统的未来版本兼容。

Brass Tacks - 通常不建议对 UI 元素进行子类化。

After much research, two things are common consensus:

(1) If you find yourself looking for ways to subclass a built-in UI element for special the chances are that you're doing something wrong, or at very least, there is a better way to do what you're trying to do.

(2) The reason to follow the interface guidelines is to be more future-compatible. There is no guarantee that a sub-classed UI element will be compatible with future versions of the OS.

Brass Tacks - subclassing UI elements is generally not advised.

↘紸啶 2024-10-27 05:16:50

您可能想查看 Matt Gemmell 的 MAAttachedWindow。

http://mattgemmell.com/2007/10/03/maattachedwindow-nswindow-subclass

You might want to check out Matt Gemmell's MAAttachedWindow.

http://mattgemmell.com/2007/10/03/maattachedwindow-nswindow-subclass

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文