Instance Method

collectionView(_:targetIndexPathForMoveFromItemAt:toProposedIndexPath:)

Asks the delegate for the index path to use when moving an item.

Declaration

optional func collectionView(_ collectionView: UICollectionView, targetIndexPathForMoveFromItemAt originalIndexPath: IndexPath, toProposedIndexPath proposedIndexPath: IndexPath) -> IndexPath

Parameters

collectionView

The collection view making the request.

originalIndexPath

The item’s original index path.

proposedIndexPath

The proposed index path of the item.

Return Value

The index path you want to use for the item. If you do not implement this method, the collection view uses the index path in the proposedIndexPath parameter.

Discussion

During the interactive moving of an item, the collection view calls this method to see if you want to provide a different index path than the proposed path. You might use this method to prevent the user from dropping the item in an invalid location. For example, you might prevent the user from dropping the item in a specific section.

See Also

Handling Layout Changes

func collectionView(UICollectionView, targetContentOffsetForProposedContentOffset: CGPoint) -> CGPoint

Gives the delegate an opportunity to customize the content offset for layout changes and animated updates.