How to intercept a long press on a UITextView?

Total Objective-C / Cocoa Click here noob, beware.

I try to intercept when the user clicks on the UITextView for a long time (then a magnifying glass appears with the caret positioner) and then releases the touch, i.e. when the options "Select" and "Select All" usually appear after the magnifying glass. I want to replace this with my own action, which is then executed.

Is it possible?

+6
objective-c iphone cocoa-touch uitextview
source share
3 answers

You can try something like this:

Disable built-in long press recognition

for (UIGestureRecognizer *recognizer in textView.gestureRecognizers) { if ([recognizer isKindOfClass:[UILongPressGestureRecognizer class]]){ recognizer.enabled = NO; } } 

Then add your

 UILongPressGestureRecognizer *myLongPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:<your target> action:@selector(<your custom handler>)]; [textView addGestureRecognizer:myLongPressRecognizer]; [myLongPressRecognizer release]; 
+14
source share

A quick version of @Altealice code to disable the integrated continuous printing recognizer:

 if let actualRecognizers = self.sourcesTextView.gestureRecognizers { for recognizer in actualRecognizers { if recognizer.isKindOfClass(UILongPressGestureRecognizer) { recognizer.enabled = false } } } 

This solution works, but be careful that it will disable textView interaction, so links will not be highlighted when clicked and the text will not be available.

+1
source share

if you remove [LongPressgesture setMinimumPressDuration:2.0]; this will work .. since the tab call will be called to start editing textField ... or just implement this delegate function gesture

 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return YES; } 
0
source share

All Articles