我可以通过编程方式打开NSMenu吗? [英] Can I open an NSMenu programatically?
问题描述
就像标题中所说的那样,我想每隔一定的时间自动打开菜单.最好从程序本身内部,因为我确定我可以使用applescripts + cron手动执行某些我不想使用的操作.
Like the title says, I want to automatically open the menu at certain intervals. Preferably from within the program itself, as I am sure I could do something manually with applescripts+cron, which I don't want to use.
我正在谈论OSX菜单栏中的菜单/按钮/其他内容.只是要清楚.没有自定义视图,只是一个普通的nsmenu.
I am talking about a menu/button/whatever from the OSX menubar. Just to be clear. No custom views, just a plain nsmenu.
推荐答案
对于打开NSStatusItem菜单,我发现在 NSStatusItem
.这样我就不必担心正确地将事件或视图传递给 popUpContextMenu
.像这样:
For opening an NSStatusItem menu, I found it easier to call the performClick
method on the button belonging to the NSStatusItem
. That way I didn't have to worry about properly passing an event or view to popUpContextMenu
. Something like this:
statusItem.button?.performClick(nil)
这篇关于我可以通过编程方式打开NSMenu吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!