如何在swift 3中检测文本视图开始编辑和结束编辑 [英] How to detect text view begin editing and end editing in swift 3

查看:18
本文介绍了如何在swift 3中检测文本视图开始编辑和结束编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在objective-c 中找到了相关的问题和答案,但是我找不到快速解决这个问题的正确方法?是否有检测与 swift 中提交的文本相同的文本视图的方法?

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.

任何帮助将不胜感激.注意:我使用的是 swift 3.

Any help would be appreciated. Note: I'm using swift 3.

推荐答案

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

}

还要确保您的 UITextView 的委托设置为 self 或这些方法在您的应用程序中的任何位置

Also make sure your UITextView's delegate is set to self or wherever these methods are in your app

这篇关于如何在swift 3中检测文本视图开始编辑和结束编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆