我正在构建一个状态栏应用程序,并希望根据用户是单击左键还是单击右键来调用不同的操作。这是我到目前为止所拥有的:
var statusItem = NSStatusBar.system().statusItem(withLength: -1)
statusItem.action = #selector(AppDelegate.doSomeAction(sender:))
let leftClick = NSEventMask.leftMouseDown
let rightClick = NSEventMask.rightMouseDown
statusItem.button?.sendAction(on: leftClick)
statusItem.button?.sendAction(on: rightClick)
func doSomeAction(sender: NSStatusItem) {
print("hello world")
}
我的函数没有被调用,我找不到我们的原因。我很感激任何帮助!