2016-10-15 68 views
0

我創建了一個NSStatusBarItem和右鍵彈出菜單的(程序生成)NSMenu斯威夫特:NSStatusItem之後剩下的突出右鍵單擊

let statusBarItem = NSStatusBar.system().statusItem(withLength: -1) 
statusBarItem.action = #selector(AppDelegate.statusBarItemAction(sender:)) 

let menu = NSMenu() 
var menuItem = NSMenuItem() 
menuItem.action = #selector(AppDelegate.customItemAction) 
menu.addItem(menuItem) 

func statusBarItemAction(sender: NSStatusItem) { 
    let mouseEvent = NSEvent.pressedMouseButtons() 
    if mouseEvent == 2 { 
     // right click 
     lxStatusBarItem.popUpMenu(menu) 
    } 
} 

func customItemAction() { 
    // do something 
} 

一切工作正常,除了statusBarItem保持customItemAction後強調被稱爲:

enter image description here

我該如何解決這個問題?

回答

0

我發現設置statusItem.button?.isHighlighted = false有助於消除高光。在你的情況下,這看起來像這樣:

func customItemAction() { 
    // do something 
    statusBarItem.button?.isHighlighted = false 
    ... 
}