Right-click on a NSStatusItem

半城伤御伤魂 提交于 2020-02-03 11:01:50

问题


I have a NSStatusItem and I want to popup a menu by rightclicking the item. I subclassed a NSView and overwrote the - (void)rightMouseDown:(NSEvent *)event method. I also implemented - (void)mouseDown:(NSEvent *)event for looking at the modifierflags. My problem is, that the view does not recieve the NSRightMouseDown-Event. And I don't know why? Any ideas how to get this event? Naturally I added the custom view to the statusitem.

- UPDATE -
Additional information: I have added a NSImageView to my custom view's subviews.

- UPDATE 2 -
Additional information: It conforms to the NSMenuDelegate protocol.


回答1:


Ok. Problem solved. The problem was the NSImageView. I subclassed it and now I redirect all mouseDown and rigthMouseDown events to its superview (my custom view).



来源:https://stackoverflow.com/questions/2169454/right-click-on-a-nsstatusitem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!