我在 objective-c 中找到了相关的问题和答案,但我找不到用 swift 解决这个问题的正确方法?是否有方法可以检测与 swift 中提交的文本相同的 TextView ?
我想解决通过键盘隐藏 TextView 的问题。为此,我需要一种方法来检测开始和结束编辑 TextView 。
如有任何帮助,我们将不胜感激。 注意:我使用的是 swift 3。
最佳答案
正如 Bawpotter 所说,“使用 UITextView 的委托(delegate)方法”。这是它们在 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
}
还要确保您的 UITextView 的委托(delegate)设置为 self
或这些方法在您的应用中的任何位置
关于swift - 如何检测 TextView 在 swift 3 中开始编辑和结束编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41476216/