Last active
January 4, 2018 13:13
-
-
Save paul1893/9237f1ff79f1836a06ab028cd972a74a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func collectionView(_ collectionView: UICollectionView, performDropWith coordinator: UICollectionViewDropCoordinator) { | |
let destinationIndexPath = coordinator.destinationIndexPath ?? IndexPath(item: 0, section: 0) | |
coordinator.session.progressIndicatorStyle = .none | |
for item in coordinator.items { | |
let itemProvider = item.dragItem.itemProvider | |
guard itemProvider.canLoadObject(ofClass: UIImage.self) else { continue } | |
var placeholderContext: UICollectionViewDropPlaceholderContext? = nil | |
let progress = itemProvider.loadObject(ofClass: UIImage.self, completionHandler: { (object, error) in | |
DispatchQueue.main.async { | |
if let image = object as? UIImage { | |
placeholderContext?.commitInsertion(dataSourceUpdates: { (placeholderIndexPath) in | |
self.imagesArray.insert(image, at: placeholderIndexPath) | |
}) | |
} else { | |
placeholderContext?.deletePlaceholder() | |
} | |
} | |
}) | |
let dropPlaceholder = UICollectionViewDropPlaceholder(insertionIndexPath: destinationIndexPath, reuseIdentifier: "PlaceholderCell") | |
dropPlaceholder.previewParametersProvider = { (cell) in | |
// Configure your placeholder cell here ... | |
// e.g: guard let placeholderCell = cell as? YourCustomPlaceholderCollectionViewCell else { return nil } | |
return UIDragPreviewParameters() | |
} | |
placeholderContext = coordinator.drop(item.dragItem, to: dropPlaceholder) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment