views:

29

answers:

1

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

I'm trying to intercept when a user long presses on a UITextView (a magnifying glass then appears with the caret positioner) and then releases the touch, i.e. when normally the "Select" and "Select All" Options appear, after the magnifying glass. I want to replace this with my own custom action that is then performed.

Is this possible?

A: 

You can try something like this:

Disable the built-in long press recognizer

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

Then add your own

UILongPressGestureRecognizer *myLongPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:<your target> action:@selector(<your custom handler>)]; 
[textView addGestureRecognizer:myLongPressRecognizer];
[myLongPressRecognizer release];
Altealice
This looks good...but is there any way for me to keep the magnifying glass? What I'm mainly interested in is the release of the long press AFTER the magnifying glass-
Epaga
Hmm, haven't tried that before. You can try overriding the method that handles the magnifying glass to add your handling when it ends, but it's probably a private method, so that may not work out well with Apple's review team. The other way is to re-implement the magnifying glass yourself.
Altealice