How do I detect if a drag operation was cancelled using NSDraggingInfo or similar?
I've created a subclass of NSImageView and implemented the informal protocol for dragging images between other instances of the same class. I am keeping a reference to the image of the view prior to the dragging operation and am able to set it back to said image given certain criteria.
However, I can'开发者_如何学编程t seem to detect if the dragging operation was cancelled. I know that the draggingEnded method is called but it is also called when a drag was successful. Any ideas?
I encountered a similar requirement. The fact that you can examine the operation
argument passed to the NSDraggingSource protocol method draggedImage:endedAt:operation:
to detect drag cancellation is not very well documented.
In the draggedImage:endedAt:operation:
method just add the following check:
if (operation == NSDragOperationNone)
return;
// Otherwise perform any drag completion tasks.
精彩评论