问题
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?
回答1:
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 UITextField
s.
来源:https://stackoverflow.com/questions/12296262/uitextview-gesture-tap-recognizer-not-working-after-text-begins-to-edit