UITapGestureRecognizer on a text field not as expected

前端 未结 2 1062
孤街浪徒
孤街浪徒 2021-01-22 11:50

In my class I have 11 UITapGestureRecognizers in an array textViewRecognizer attached to 11 out of 100 UITextFields in an array boxArray. When a Textfield is tapped containing a

相关标签:
2条回答
  • 2021-01-22 12:07

    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!

    0 讨论(0)
  • 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
    }
    
    0 讨论(0)
提交回复
热议问题