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 dragInteraction(_ interaction: UIDragInteraction, itemsForBeginning session: UIDragSession) -> [UIDragItem] { | |
let image:UIImage = getImage() | |
let provider = NSItemProvider(object: image) | |
let item = UIDragItem(itemProvider: provider) // Build your drag item | |
item.localObject = image | |
return [item] | |
} |
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 dragInteraction(_ interaction: UIDragInteraction, itemsForBeginning session: UIDragSession) | |
let itemProvider = NSItemProvider() | |
itemProvider.registerFileRepresentation(forTypeIdentifier: kUTTypeJPEG as String, fileOptions: [.openInPlace], visibility: .all){ completionHandler in | |
//Get Url | |
let url = Attachement.url(forName: self.contactCard.name) | |
completionHandler(url, true, nil) | |
return nil | |
} | |
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 dragInteraction(_ interaction:UIDragInteraction, previewForLifting item:UIDragItem, session:UIDragSession) -> UITargetedDragPreview? { | |
let imageView = UIImageView(image: UIImage(named: "MyDragImage")) | |
let dragView = interaction.view! | |
let dragPoint = session.location(in: dragView) | |
let target = UIDragPreviewTarget(container: dragView, center: dragPoint) | |
return UITargetedDragPreview(view: imageView, parameters:UIDragPreviewParameters()) | |
} |
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 tableView(_ tableView: UITableView, dragPreviewParametersForRowAt indexPath: IndexPath) -> UIDragPreviewParameters? { | |
let parameters = UIDragPreviewParameters() | |
parameters.visiblePath = yourCustomBezierPath | |
return parameters | |
} |
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 | |
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, dropSessionDidUpdate session: UIDropSession, withDestinationIndexPath destinationIndexPath: IndexPath?) -> UICollectionViewDropProposal { | |
if session.localDragSession != nil { | |
return UICollectionViewDropProposal(operation: .move, intent: .insertAtDestinationIndexPath) | |
} else { | |
return UICollectionViewDropProposal(operation: .copy, intent: .insertAtDestinationIndexPath) | |
} | |
} |
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 tableView(_ tableView: UITableView, itemsForAddingTo session: UIDragSession, at indexPath: IndexPath, point: CGPoint) -> [UIDragItem] { | |
// Return an empty array to handle the tap normally or array to add items already got from itemsForBeginning | |
let image = arrImg[indexPath.row] | |
let provider = NSItemProvider(object: image as NSItemProviderWriting) | |
let item = UIDragItem(itemProvider: provider) | |
item.localObject = image | |
return [item] | |
} |
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 dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession) { | |
// 1) Première possibilité | |
let progress = session.loadObjects(ofClass: UIImage.self) { imageItems in | |
let images = imageItems as! [UIImage] | |
self.selectedImageView.image = images.first | |
} | |
// 2) Seconde possibilité | |
for item in session.items { | |
item.itemProvider.loadObject(ofClass: UIImage.self) { (object, error) in |
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 dropInteraction(_ interaction: UIDropInteraction, sessionDidUpdate session: UIDropSession) -> UIDropProposal { | |
let dropLocation = session.location(in: view) | |
let operation: UIDropOperation | |
if selectedImageView.frame.contains(dropLocation) { | |
if session.localDragSession == nil { // Drag come frome the app | |
operation = .copy | |
} else { // Drag come from a third app | |
operation = .move | |
} |
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 dropInteraction(_ interaction: UIDropInteraction, canHandle session: UIDropSession) -> Bool { | |
let identifiers = [kUTTypeImage as String] // Can be very specific [kUTTypeImagePNG as String] (Only PNG) | |
return session.hasItemsConforming(toTypeIdentifiers: identifiers) && session.items.count == 1 | |
} |