2

In my project ,there is a demand about UITextView. when I tap the link in UITextView, our app should open a webview Controller to show the linked content; when i long press the link in UITextView, our app should show some menu about copy and paste.now i can implement the second situation in UIInputViewDelegate

(BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange

although the shouldInteractWithURL is fired, i can't recognize the relative tag between the tap event and long press event.

then i breakpoint at the end of

(BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange

method,and i use lldb to find some information about tap event and long press event as follow:

long press event:

frame #1: 0x0000000112b46214 UIKit`-[_UITextViewInteractableLink allowInteraction] + 165
    frame #2: 0x0000000112b452c3 UIKit`-[_UITextViewInteractableItem handleLongPress] + 22
    frame #3: 0x0000000112b45055 UIKit`-[UITextView(LinkInteraction) validateInteractionWithLinkAtPoint:] + 287
    frame #4: 0x00000001125edac9 UIKit`-[UITextInteractionAssistant(UITextInteractionAssistant_Internal) longDelayRecognizer:] + 281
    frame #5: 0x00000001125dbb28 UIKit`_UIGestureRecognizerSendTargetActions + 153

tap event:

frame #1: 0x0000000112b46214 UIKit`-[_UITextViewInteractableLink allowInteraction] + 165
    frame #2: 0x0000000112b45181 UIKit`-[_UITextViewInteractableItem handleTap] + 33
    frame #3: 0x0000000112b45055 UIKit`-[UITextView(LinkInteraction) validateInteractionWithLinkAtPoint:] + 287
    frame #4: 0x00000001125ed782 UIKit`-[UITextInteractionAssistant(UITextInteractionAssistant_Internal) 

i find out some difference about the two event;handleTap or handleLongPress is fired in different scene. so any solution to capture the long press event or disable the system's long press event then add my own long press event to handle long event on linkedText in UITextView?

Liju Thomas
  • 1,054
  • 5
  • 18
  • 25
terry.king
  • 21
  • 2
  • Possible duplicate of [How to intercept long press on UITextView without disabling context menu?](http://stackoverflow.com/questions/9788535/how-to-intercept-long-press-on-uitextview-without-disabling-context-menu) – Larme May 12 '16 at 09:11
  • yes, this implement obviously can interrupt the long press event.but how can i interactive with tap click event? finally, i detect hyperlink by myself,and add longGestureRecognizer, TapGestureRecognizer for UITextView.when some gestureRecognizer occur,i get the tap position, find out the attributes at tap position,then get the hyperlink text range and do something i want – terry.king May 16 '16 at 05:54
  • Have you solved it? Does anyone have solution for this? shouldInteractWith method gets called for both tap & longpress gesture. But how can we differentiate the gesture? so that we can have respective custom implementation – Sathyan Jun 21 '22 at 12:37

1 Answers1

0

Why go an do long press if its hyperlink it should work on just one check here https://stackoverflow.com/a/37207783/5772601

Community
  • 1
  • 1
  • yes, it is a demand. long press to dialog a menu which contains a copy item,and tap to jump to a webview controller – terry.king May 16 '16 at 05:39