Contents

collectionView(_:draggingImageForItemsAt:with:offset:)

Creates and returns a drag image to represent the specified items during a drag.

Declaration

@MainActor optional func collectionView(_ collectionView: NSCollectionView, draggingImageForItemsAt indexPaths: Set<IndexPath>, with event: NSEvent, offset dragImageOffset: NSPointPointer) -> NSImage

Parameters

  • collectionView:

    The collection view making the request.

  • indexPaths:

    The index paths of the items being dragged.

  • event:

    The mouse-down event that began the drag operation. You can use the mouse location when determining what value to return in the dragImageOffset parameter.

  • dragImageOffset:

    The offset value to use when positioning the image. On input, the point is Nszeropoint, which centers the returned image under the mouse. Your method can return a different point that repositions the drag image by the specified offset values.

Return Value

The image to use for the dragged items.

Discussion

Your implementation of this method should create an appropriate image to use during the drag operation. The collection view places the center of your image at the current mouse location. Update the value in the dragImageOffset parameter to shift the position of your image by the specified amount.

If you do not implement this method, the collection view uses the drag image returned by the draggingImageForItems(at:with:offset:) method instead.

See Also

Drag and Drop Support