如何在swift 3中检测文本视图开始编辑和结束编辑

Zus*_*kin 4 textview swift

我在objective-c中找到了相关的问题和答案但是我找不到一个适当的方法用swift?是否有方法检测文本视图与swift中提交的文本相同?

我想通过键盘解决隐藏文本视图的问题.为此,我需要一种方法来检测开始和结束编辑文本视图.

任何帮助,将不胜感激.注意:我正在使用swift 3.

Gar*_*aye 7

正如Bawpotter所说,"使用UITextView的委托方法".这是他们在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

}
Run Code Online (Sandbox Code Playgroud)

还要确保您的UITextView代理设置为self应用程序中的这些方法或位置