Ios UICollectionView更改放置占位符索引路径
我想使用拖放实现以下UX。简介:用户应该只能在末尾插入项目Ios UICollectionView更改放置占位符索引路径,ios,swift,uicollectionview,drag-and-drop,Ios,Swift,Uicollectionview,Drag And Drop,我想使用拖放实现以下UX。简介:用户应该只能在末尾插入项目 用户可以从任何源拖动项目并将其指向集合视图 当项目悬挂在视图上方时,占位符将显示在特定位置,例如在末端 当用户释放该项时,它将设置为占位符索引的动画 我可以通过以下方式实施步骤3: 问题是更改占位符索引,默认情况下该索引位于拖动项下。我们可以提供一个建议。但是没有指定索引路径的变量。请尝试使用collectionView(\uuU2:targetIndexPathForMoveFromItemAt:TopProposedIndexPa
问题是更改占位符索引,默认情况下该索引位于拖动项下。我们可以提供一个建议。但是没有指定索引路径的变量。请尝试使用
collectionView(\uuU2:targetIndexPathForMoveFromItemAt:TopProposedIndexPath:)
。虽然它不是最后一个索引,但返回originalIndexPath
func collectionView(_ collectionView: UICollectionView, targetIndexPathForMoveFromItemAt originalIndexPath: IndexPath, toProposedIndexPath proposedIndexPath: IndexPath) -> IndexPath {
guard proposedIndexPath.item == lastItemIndex // Here should be some logic to calculate the last index
else { return originalIndexPath }
return proposedIndexPath
}
但是,对于某些实现,此函数从未被调用。例如,当您使用UICollectionViewController时。在这种情况下,在集合视图中返回.cancel关于drop的建议-UICollectionViewDropProposal(操作:.cancel,意图:.InsertatDestinationIndepath)
(\uuuuU9:DropSessionIDUpdate:WithDestinationIndepath:)
函数:
func collectionView(_ collectionView: UICollectionView,
dropSessionDidUpdate session: UIDropSession,
withDestinationIndexPath destinationIndexPath: IndexPath?)
-> UICollectionViewDropProposal {
guard destinationIndexPath?.item != lastItemIndex // Here should be some logic to calculate the last index
else {
return UICollectionViewDropProposal(
operation: .cancel,
intent: .insertAtDestinationIndexPath)
}
return UICollectionViewDropProposal(
operation: .move,
intent: .insertAtDestinationIndexPath)
}
稍后我会测试你的答案,并给出一些有意义的反馈。
func collectionView(_ collectionView: UICollectionView,
dropSessionDidUpdate session: UIDropSession,
withDestinationIndexPath destinationIndexPath: IndexPath?)
-> UICollectionViewDropProposal {
guard destinationIndexPath?.item != lastItemIndex // Here should be some logic to calculate the last index
else {
return UICollectionViewDropProposal(
operation: .cancel,
intent: .insertAtDestinationIndexPath)
}
return UICollectionViewDropProposal(
operation: .move,
intent: .insertAtDestinationIndexPath)
}