在 UIView 上调用 endEditing [英] Calling endEditing on a UIView

查看:39
本文介绍了在 UIView 上调用 endEditing的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有两个 UITextView 的 tableView.用户可以通过点击+"按钮添加任意数量的单元格.tableView 从一行(单元格)开始.假设用户向两个 textViews 添加了一些信息,然后点击加号按钮并滚动到它.当用户滚动时,我调用这个函数来关闭键盘,这样它就不会妨碍:

I have a tableView with two UITextViews. The user can add as many cells as they want by tapping on a "+" button. The tableView starts out with one row (cell). Lets say the user adds some information to the two textViews and then taps the plus button and scrolls to get to it. I call this function to dismiss the keyboard when a user scrolls so it isn't in the way:

override func scrollViewDidScroll(scrollView: UIScrollView) {

    self.view.endEditing(true)

}

现在,键盘消失,用户点击第二行的文本字段.tableView 跳起来(我认为是为了适应键盘),但是无法编辑 textField(没有光标和键盘不会出现).如果我回到第一行(第 0 行),键盘就会出现,我可以编辑 textView.为什么会这样?

Now, the keyboard disappears and the user goes to tap on the second row's text field. The tableView jumps up (I think to accommodate the keyboard), but the textField can't be edited (no cursor and keyboard doesn't appear). If I go back up to the first row (row 0), the keyboard appears and I can edit the textView. Why is this happening?

推荐答案

scrollView 子类(例如 TableViews)上有一个属性

There is a property on scrollView subclasses (e.g TableViews)

tableView.keyboardDismissMode = .OnDrag

一旦用户开始向下拖动,它就会关闭键盘

Once the user begins a descending drag it dismisses the keyboard

这篇关于在 UIView 上调用 endEditing的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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