How to stop mouse drag events from moving entire window? [cocoa]
I think this should be a very easy one, but I cant find the answer on the docs.
I want to stop mouse dragging events which are in (or start in) my custom nsview subclass from causing the window to be dragged around the screen.开发者_JS百科 How can I tell the window to stay still so i can interact with the view instead of dragging the whole window around? thanks.
In addition to the matter of whether you handle mouseDragged
, you may need to override mouseDownCanMoveWindow
to return NO, or override isOpaque
to return YES.
You need to implement mouseDragged:
in your view. As documented, NSView's implementation simply passes the message to the next responder, which means that it will end up hitting the window. (Why? See “The Responder Chain” in the Cocoa Event-Handling Guide.) Responding to the message yourself prevents that, as long as you don't call up to the superclass implementation.
精彩评论