Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSView Subviews interrupting drag operation

I have an NSView which is registered for a drag operation.

In that view I have a subclassed NSScrollView, which in itself has an NSImageView in it.

When dragging onto the original NSView, everything is fine, other than when I drag over the aforementioned NSImageView, which seems to interupt the drag and I cannot drop onto it (or in fact, the view underneath it.

The NSScrollView appears to ignore the drag and allows that to go through to the underlying NSView, but how can I do that for the NSImageView so that the Drag/Drop registers through itself, it's superview (the NSScrollView) and onto the underlying NSView.

like image 631
mootymoots Avatar asked Jan 24 '11 13:01

mootymoots


2 Answers

You can unregister the NSImageView as a dragging destination. Its superview will then handle the dragging session, if it's set up to do that.

[imageView unregisterDraggedTypes];
like image 101
Steven Vandeweghe Avatar answered Sep 22 '22 11:09

Steven Vandeweghe


Oh, thanks so much @Steven!

Swift 4.2 and @IBOutlets:

@IBOutlet private weak var imageView: NSImageView! {
  didSet {
    imageView.unregisterDraggedTypes()
  }
}

Long story:
I had this NSCollectionView, which loaded a custom NSCollectionViewItem from a XIB file.

The collection accepts drop operations (collectionView.registerForDraggedTypes([.fileURL])).
But as soon as something was dropped into it and the custom cell was "dequeued" (makeItem(withIdentifier:for:)) -- drop operations stopped working above that specific cell.

unregisterDraggedTypes() fixes the issue indeed. 🎉

like image 26
backslash-f Avatar answered Sep 21 '22 11:09

backslash-f