0

iOS 11 introduced the ability to drag and drop text and images. So for example I can select some text, then press and hold it again and drag it into a text field or another application.

In Swift code, how can I detect when the user starts dragging some selection? The finger moves, so I tried a drag gesture handler but that does not work, the dragging of the selection is on some other "layer" that does not trigger it.

Streetlamp
  • 1,537
  • 2
  • 15
  • 27
  • Have you looked at `UITextDragDelegate` and `UITextDropDelegate`? Apple docs: [Drag and drop customization](https://developer.apple.com/documentation/uikit/views_and_controls/drag_and_drop_customization) – DonMag Jul 24 '23 at 19:59
  • @DonMag do you know if there is an equivalent for images? – Streetlamp Jul 24 '23 at 21:49
  • The docs state: *The UITextField and UITextView classes provide built-in support for dragging and dropping text and images.* ... are you looking for something else? – DonMag Jul 24 '23 at 22:01
  • @DonMag Hmm, that does answer this question, but what I am actually trying to do is solve this issue: https://stackoverflow.com/questions/76751649/ and I was hoping for a solution that isn't specific to `UITextField` and `UITextView`. If you answer with the docs, I will mark that as answer and close this question though. – Streetlamp Jul 24 '23 at 22:30
  • I haven't look at the `iOS 17` new APIs yet... but have you watched this video? [Lift subjects from images in your app](https://developer.apple.com/videos/play/wwdc2023/10176/) ... very possibly you'll find something there. – DonMag Jul 25 '23 at 12:34
  • I have, yeah, sadly they do not cover this, instead using a UIHoverGestureRecognizer with an Apple Pen to get around this – Streetlamp Jul 26 '23 at 15:04

0 Answers0