UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Question: UIGestureRecognizer on textView

Forums > Swift

Hi, Do you guys know a way of adding a UIGestureRecognizer on a textView without killing the editing feature of the textView? What am I trying to achieve is when the user is typing some text the "Done" button should be visible (like in the iOS Notes app). When he is done hide the button. The thing is that I applied a UIGestureRecognizer on the textView but it kills the editing proprety of the textView. Below is my code:

    override func viewDidLoad() {
        super.viewDidLoad()

        textView.text = noteContent

        let tappedOnText = UITapGestureRecognizer(target: self, action: #selector(textTapped))
        tappedOnText.delegate = self
        textView.addGestureRecognizer(tappedOnText)

    }
    @IBAction func textTapped(_ sender: Any) {
        showNavigationButtons()
        print("The text view has been tapped!")
    }
extension DetailViewController: UIGestureRecognizerDelegate {
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
        return true
    }

}

I did some research but I can't figure it out. Thank you and enjoy your day!

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.