UITapGestureRecognizer on a text field not as expected

江枫思渺然 提交于 2019-12-02 02:30:41

It sounds like you want to remove the automatic editing behavior on a UITextView. You can grab more control over that with the textViewShouldBeginEditing(_ textView: UITextView) -> Bool UITextViewDelegate method, documented here.

If you return false for that method, this should avoid needing a double tap to get to your gesture recognizer. Depending on your use case, you can then "allow" the tap to go to the text view by returning true for the textView you want to be actually edited.

While I'm not 100% clear on the first responder part of your question, since the textView won't be grabbing first responder if it's not starting it's editing mode, this should address that concern I believe. Good luck!

I would add a Tag to my UITextView and set the UITextViewDelegate to my ViewController.

Then I would add the following Delegate method:

func textViewShouldBeginEditing(_ textView: UITextView) -> Bool {
    print("Textview tag: ", textView.tag)
    return false
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!