在 uitextview 中消失键盘

编程入门 行业动态 更新时间:2024-10-28 13:26:04
本文介绍了在 uitextview 中消失键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-29 03:21:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1183601.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:键盘   uitextview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!