I found related questions and answers in objective-c but I couldn't find a proper way to this with swift? Is there methods to detect for text view same as text filed in swift?
I want to solve the issue hiding text view by keyboard. For that I need a way to detect start and end edit text view.
Any help would be appreciated. Note: I'm using swift 3.
Just as Bawpotter said, "Use the delegate methods for UITextView". Here is what they look like in Swift 3:
func textViewDidBeginEditing(_ textView: UITextView) {
// Run code here for when user begins type into the text view
}
func textViewDidEndEditing(_ textView: UITextView) {
// Run code here for when user ends editing text view
}
Also make sure your UITextView's delegate is set to self
or wherever these methods are in your app
Conform your ViewController class to UITextViewDelegate and then write
textView.delegate = self
in your viewDidLoad(). After that write delegate methods for your textView as:
func textViewShouldBeginEditing(_ textView: UITextView) -> Bool {
// your code here
}
func textViewDidBeginEditing(_ textView: UITextView) {
// your code here
}
func textViewShouldEndEditing(_ textView: UITextView) -> Bool {
// your code here
}
func textViewDidEndEditing(_ textView: UITextView) {
// your code here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With