Superview as a drag object if subview rejects it

Consider a view ( parent) with a preview ( child). Both registered for the drag type NSFilenamesPboardType.

parentHe is only interested in image files and childin audio files. If they discover a file of the appropriate type in draggingEntered:, they return NSDragOperationCopy. If not, they return NSDragOperationNone.

childoverlaps parent, and when the drag reaches child, it parentreceives a message draggingExited:, regardless of whether it is interested in childdragging or not.

How can I do parentget drag and drop if I childdo not want it?

+5
source share
3

, :

[self.superview yourmethod];

childs.

, , :

[super yourmethod];
+3

, :

  • @Thomas, , , .

  • ([childView unregisterDraggedTypes]), . , , , . , . . , draggingUpdated:, .

+2

, , NSFilenamesPboardType.

UIResponderChain, subviews

- (NSView*) dragTest:(id< NSDraggingInfo >)sender;

nil, , subview ( ) .

Now back to parentview, when draggingEntered: triggered, count the location and find out what form it is on, call dragTest: to check if the corresponding subview wants to process it. Let the returned non-zero representation handle the event, otherwise handle it in the parent.

This method will be useful if you have many levels of subviews.

+1
source

All Articles