Search code examples
uitextviewuigesturerecognizertap

UITextView gesture tap recognizer not working after text begins to edit


I am setting up a UITextView with a tap gesture recognizer so that I can do various things after the textView is tapped. For one I want the text view to be the "selected" view after it is tapped, like so:

selectedTextView = (UITextView *)recognizer.view;

It works, except that after the text view goes into text edit mode, reveling the keyboard and allowing text editing, thereafter my custom tap gesture recognizer no longer works.

Any way around this?


Solution

  • You might just need to return YES for -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer for your recognizer.

    It would appear that when the UITextView becomes the firstResponder (keyboard appears), that Apple's code removes all gesture recognizers from that UIView. You can add your recognizers again in UITextViewDelegate's –textViewDidBeginEditing:. It also appears to remove recognizers when resigning firstResponder so you'll have to also add it in -textViewDidEndEnding:

    The same is true for UITextFields.