targetIndexPath(forInteractivelyMovingItem:withPosition:)
Retrieves the index path to for an item when it is at the specified location in the collection view’s bounds.
Declaration
func targetIndexPath(forInteractivelyMovingItem previousIndexPath: IndexPath, withPosition position: CGPoint) -> IndexPathParameters
- previousIndexPath:
The previous index path of the item. Use this value to identify the item.
- position:
The target point in the collection view’s bounds. Use this value to compute the new index path for the item.
Return Value
The index path corresponding to the specified location in the collection view.
Discussion
During interactive movement of an item, this method maps points in the collection view’s bounds rectangle to index paths that correspond to the locations of those points. The default implementation of this method searches for an existing cell at the specified location and returns the index path of that cell. If there are multiple cells at the same location, the method returns the topmost cell—that is, the cell whose zIndex layout attribute value is greatest.
You can override this method as needed to change how the index path is determined. For example, you might return the index path of the cell that has the lowest zIndex value instead of the highest. If you override this method, you do not need to call super.
See Also
Responding to collection view updates
prepare(forCollectionViewUpdates:)finalizeCollectionViewUpdates()indexPathsToInsertForSupplementaryView(ofKind:)indexPathsToInsertForDecorationView(ofKind:)initialLayoutAttributesForAppearingItem(at:)initialLayoutAttributesForAppearingSupplementaryElement(ofKind:at:)initialLayoutAttributesForAppearingDecorationElement(ofKind:at:)indexPathsToDeleteForSupplementaryView(ofKind:)indexPathsToDeleteForDecorationView(ofKind:)finalLayoutAttributesForDisappearingItem(at:)finalLayoutAttributesForDisappearingSupplementaryElement(ofKind:at:)finalLayoutAttributesForDisappearingDecorationElement(ofKind:at:)