Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private func reorderItems(coordinator: UICollectionViewDropCoordinator, destinationIndexPath: IndexPath, collectionView: UICollectionView)
- {
- let items = coordinator.items
- if items.count == 1, let item = items.first, let sourceIndexPath = item.sourceIndexPath
- {
- var dIndexPath = destinationIndexPath
- if dIndexPath.row >= collectionView.numberOfItems(inSection: 0)
- {
- dIndexPath.row = collectionView.numberOfItems(inSection: 0) - 1
- }
- collectionView.performBatchUpdates({
- if collectionView === self.collectionView2
- {
- self.items2.remove(at: sourceIndexPath.row)
- self.items2.insert(item.dragItem.localObject as! String, at: dIndexPath.row)
- }
- else
- {
- self.items1.remove(at: sourceIndexPath.row)
- self.items1.insert(item.dragItem.localObject as! String, at: dIndexPath.row)
- }
- collectionView.deleteItems(at: [sourceIndexPath])
- collectionView.insertItems(at: [dIndexPath])
- })
- coordinator.drop(items.first!.dragItem, toItemAt: dIndexPath)
- }
- }
- func collectionView(_ collectionView: UICollectionView, performDropWith coordinator: UICollectionViewDropCoordinator)
- {
- let destinationIndexPath: IndexPath
- if let indexPath = coordinator.destinationIndexPath
- {
- destinationIndexPath = indexPath
- }
- else
- {
- // Get last index path of table view.
- let section = collectionView.numberOfSections - 1
- let row = collectionView.numberOfItems(inSection: section)
- destinationIndexPath = IndexPath(row: row, section: section)
- }
- switch coordinator.proposal.operation
- {
- case .move:
- self.reorderItems(coordinator: coordinator, destinationIndexPath:destinationIndexPath, collectionView: collectionView)
- break
- case .copy:
- self.copyItems(coordinator: coordinator, destinationIndexPath: destinationIndexPath, collectionView: collectionView)
- default:
- return
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement