Skip to content

Instantly share code, notes, and snippets.

@YuriNachos
Last active September 8, 2017 10:58
Show Gist options
  • Select an option

  • Save YuriNachos/bafa6f9077f60d9fbeb01cf9e11d5842 to your computer and use it in GitHub Desktop.

Select an option

Save YuriNachos/bafa6f9077f60d9fbeb01cf9e11d5842 to your computer and use it in GitHub Desktop.
Code sample #3 from drag&drop tutorial
func dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession) {
for dragItem in session.items { // (1)
// (2)
dragItem.itemProvider.loadObject(ofClass: UIImage.self, completionHandler: { object, error in
// (3)
guard error == nil else { return print("Failed to load our dragged item") }
guard let draggedImage = object as? UIImage else { return } // (4)
DispatchQueue.main.async { // (5)
let imageView = UIImageView(image: draggedImage) // (6)
self.view.addSubview(imageView)
imageView.frame = CGRect(x: 0, y: 0, width: draggedImage.size.width, height: draggedImage.size.height)
let centerPoint = session.location(in: self.view)
imageView.center = centerPoint
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment