Custom Preview/Commit View Controllers When 3D Touching a Link in a UITextView
Asked Answered
C

0

7

I have a UITextView that displays an NSAttributedString that contains various links (via NSLinkAttributeName) and I want to be able to use my own view controllers as the previewing and commit view controllers rather than the default behaviour.

I assume that this is possible because the UITextItemInteraction enum, which is used in UITextViewDelegate, contains a case for 3D touching.

I have tried:

  • looking for a solution in UITextViewDelegate but the closest function to what I want, textView(_:shouldInteractWith:in:interaction:) doesn't seem to let you change the preview or commit view controllers - just disable the default behaviour

  • doing it the same way as you would with any other view and registering it for 3D touch and using previewingContext(_:viewControllerForLocation:) from UIViewControllerPreviewingDelegate, but I cant find a way to get the link that has been 3D touched

Could someone please let me know the proper way to do this?

Cointon answered 24/10, 2017 at 8:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.