在 uitextview 中消失键盘 [英] Disappear keyboard in uitextview

查看:25
本文介绍了在 uitextview 中消失键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 swift 中使用 uitextview 并且键盘消失我正在使用 uitextview 委托方法

i'm using uitextview in swift and for keyboard disappear i'm using uitextview delegate method

func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
    if(text == "\n") {
        textView.resignFirstResponder()
        return false
    }
    return true
}

但我不想使用此委托方法返回键盘 bcz 我想在下一行使用返回键.有没有其他方法可以让键盘消失?出于某种原因,我不想使用触摸事件.

but i don't want to use this delegate method to return the keyboard bcz i want to use return key for next line. is there any other ways to disappear keyboard? and for some reason i don't wana use touch event.

推荐答案

除非您使用自定义键盘,否则键盘上不能同时具有返回键和关闭键.自定义键盘可以通过设置 inputView 属性

You cannot have both a return and a dismiss key on the keyboard unless you use a custom keyboard. A custom keyboard can be added by setting the inputView property

更好的标准做法是在键盘顶部有一个按钮,让用户可以选择隐藏它.这可以通过为 UITextView 分配一个 inputAccessoryView 来完成.更多这里

A better standard practice is to have a button on top of the keyboard giving the user an option to hide it. This can be done by assigning an inputAccessoryView for the UITextView. More here

这篇关于在 uitextview 中消失键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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