Last active
September 8, 2017 10:58
-
-
Save YuriNachos/bafa6f9077f60d9fbeb01cf9e11d5842 to your computer and use it in GitHub Desktop.
Code sample #3 from drag&drop tutorial
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) { | |
| 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