UITextView gesture tap recognizer not working after text begins to edit

一个人想着一个人 提交于 2020-02-04 07:47:04

问题


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 UITextFields.



来源:https://stackoverflow.com/questions/12296262/uitextview-gesture-tap-recognizer-not-working-after-text-begins-to-edit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!