通过“动画”以编程方式单击 NSPushButton

发布于 2024-12-26 19:29:41 字数 298 浏览 4 评论 0原文

我刚刚遇到了一个我已经从其他编程语言/框架中知道的问题...... 每当用户单击键盘上的某个按钮时,他都会触发与按下 GUI 中的某个按钮时相同的操作。 (有些人称这些为“快捷方式”;D)

为了给用户视觉反馈,我想以编程方式“单击”按钮,而不是调用单击按钮时调用的相同函数。

如果我将按钮设置为 IB 中的等效键,它看起来就像我想要的那样。 此处无法执行此操作,因为如果正确的文本字段具有焦点,则应启用快捷方式。

在 NSButton 或类似的方法中找不到听起来正确的方法。 我相信你们能给我一些指导!

最好,提前致谢

I just ran into a problem I already know from other programming languages/frameworks ....
Whenever the user clicks a certain button on the keyboard, he triggers the same action than when a certain button in the GUI is pressed. ( Some guys call these "shortcuts" ;D )

To give the user an optical feedback, I would like to sorta "click" the button programmatically rather than calling the same functions that get called when the button is clicked.

If I set the button as a key equivalent in IB, it looks exactly as I want to have it.
Can't do that here as the shortcut should just be enabled if the right textfields have focus.

Couldn't find a method in NSButton or similar that sounded right.
I'm sure you guys can give me some direction!

Best and thanks in advance

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

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

发布评论

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

评论(1

请叫√我孤独 2025-01-02 19:29:41

您只需将 performClick: 发送到按钮即可。它将突出显示自己,将其操作发送到目标,然后取消突出显示自己。

[self.someButton performClick:self];

如果您确实只想手动突出显示和取消突出显示按钮,可以使用 highlight: 方法。

[self.someButton highlight:YES]; // button appears pressed
[self.someButton highlight:NO]; // button appears unpressed

You can just send performClick: to the button. It will highlight itself, send its action to its target, and then unhighlight itself.

[self.someButton performClick:self];

If you really want to just highlight and unhighlight the button manually, you can use the highlight: method.

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