Skip to content

Instantly share code, notes, and snippets.

@CibelePaulinoAndrade
Last active July 26, 2018 18:00
Show Gist options
  • Save CibelePaulinoAndrade/a42c3f9cdc68e6a5b8c165ef009f052f to your computer and use it in GitHub Desktop.
Save CibelePaulinoAndrade/a42c3f9cdc68e6a5b8c165ef009f052f to your computer and use it in GitHub Desktop.
extension ViewController: UIDropInteractionDelegate {
func dropInteraction(_ interaction: UIDropInteraction, sessionDidUpdate session: UIDropSession) -> UIDropProposal {
let location = session.location(in: self.view)
let dropOperation: UIDropOperation?
if session.canLoadObjects(ofClass: String.self) {
if dropTextView.frame.contains(location) {
dropOperation = .copy
} else if dropImageView.frame.contains(location) {
dropOperation = .forbidden
} else {
dropOperation = .cancel
}
}
else if session.canLoadObjects(ofClass: UIImage.self) {
if dropImageView.frame.contains(location) {
dropOperation = .copy
} else if dropTextView.frame.contains(location) {
dropOperation = .forbidden
} else {
dropOperation = .cancel
}
}
else {
dropOperation = .cancel
}
return UIDropProposal(operation: dropOperation!)
}
func dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession) {
if session.canLoadObjects(ofClass: String.self) {
session.loadObjects(ofClass: String.self) { (items) in
let values = items as [String]
self.dropTextView.text = values.last
}
} else if session.canLoadObjects(ofClass: UIImage.self) {
session.loadObjects(ofClass: UIImage.self) { (items) in
let images = items as! [UIImage]
self.dropImageView.image = images.last
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment