问题
I have an NSView subclass that gets initialized with an OpenGL context and has a bunch of mouse event handling (onMouseDown, etc...). I have an app using it which has a main Cocoa window that contains the view and all the mouse events are working properly.
However, I'm trying to use it now in another app where i have a secondary window that pops open and gets initialized with the view and while i get mouse moved evets, I don't seem to get any mouse click (or keyboard for that matter) events whatsoever.
When I click and drag on the view, the entire window moves, which im guessing has to do why i dont get any mouse events. I have acceptsFirstResponder and acceptsFirstMouse returning YES and even have hitTest returning self for good measure.
Do you guys have any ideas what could be wrong?
回答1:
You need to return NO from -mouseDownCanMoveWindow in your NSView subclass.
来源:https://stackoverflow.com/questions/1490331/mouse-click-events-in-an-nsview-subclass