collectionView(_:validateDrop:proposedIndex:dropOperation:)
Validates the specified location to see if it is a valid drop target.
Declaration
@MainActor optional func collectionView(_ collectionView: NSCollectionView, validateDrop draggingInfo: any NSDraggingInfo, proposedIndex proposedDropIndex: UnsafeMutablePointer<Int>, dropOperation proposedDropOperation: UnsafeMutablePointer<NSCollectionView.DropOperation>) -> NSDragOperationParameters
- collectionView:
The collection view that send the message.
- draggingInfo:
An object containing details about this dragging operation.
- proposedDropIndex:
The proposed drop index. This parameter is passed by-reference and can be modified retarget the drop operation.
- proposedDropOperation:
The proposed drop operation. This parameter is passed by-reference and can be modified to change the drop operation.
Return Value
A value that indicates which dragging operation to perform. Return NSDragOperationNone to disallow the drop.
Discussion
Based on the mouse position, the collection view will suggest a proposed index and drop operation. These values are in/out parameters and can be changed by the delegate to retarget the drop operation.
The collection view will propose NSCollectionViewDropOn when the dragging location is closer to the middle of the item than either of its edges. Otherwise, it will propose NSCollectionViewDropBefore. You may override this default behavior by changing proposedDropOperation or proposedDropIndex.
To receive drag messages, you must first send registerForDraggedTypes(_:) to the collection view with the drag types you want to support.
You must implement this method for your collection view to be a drag destination.
See Also
Legacy Collection View Support
collectionView(_:canDragItemsAt:with:)collectionView(_:pasteboardWriterForItemAt:)collectionView(_:writeItemsAt:to:)collectionView(_:namesOfPromisedFilesDroppedAtDestination:forDraggedItemsAt:)collectionView(_:draggingImageForItemsAt:with:offset:)collectionView(_:draggingSession:willBeginAt:forItemsAt:)collectionView(_:acceptDrop:index:dropOperation:)