我正在寻找一种方法来检测何时NSStatusBarButton
右键单击(使用 Swift)并调用操作。
我目前是这样设置的:
let statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(-1)
func applicationDidFinishLaunching(aNotification: NSNotification) {
// Insert code here to initialize your application
if let button = statusItem.button {
button.image = NSImage(named: "myImage")
button.alternateImage = NSImage(named: "myImage")
button.action = Selector("myAction")
}
}
我想过使用button.rightMouseDown(<#theEvent: NSEvent#>)
(因为没有这样的“alternateAction”),但不幸的是,由于我刚刚开始编写 Mac 应用程序,我没有想出一些东西。
更新:
在寻找一种方法时,我看到一些线程告诉子类 a
NSView
,但我不知道这应该如何工作(这可能是因为我对编程真的很陌生,甚至不知道如何“子类”)。我仍然认为有一些更简单的方法可以使用它,因为statusBar
我知道的几乎每个应用程序都可以右键单击。