Swift关闭UITextView键盘

栏目: Swift · 发布时间: 6年前

内容简介:翻译自:https://stackoverflow.com/questions/28280191/swift-dismiss-uitextview-keyboard
我很难在 swift

中解雇文本视图的键盘.

我能够用以下内容解雇文本字段

@IBAction func DismissKeyboard(sender: AnyObject) 
    {
         self.resignFirstResponder()
    }

但我不确定如何用文本视图来解决它

您必须将textview.delegate设置为self并使用shouldChangeTextInRange函数在按回车时重新签名.
func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
    if text == "\n"  // Recognizes enter key in keyboard
    {
        textView.resignFirstResponder()
        return false
    }
    return true
}

翻译自:https://stackoverflow.com/questions/28280191/swift-dismiss-uitextview-keyboard


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Two Scoops of Django

Two Scoops of Django

Daniel Greenfeld、Audrey M. Roy / CreateSpace Independent Publishing Platform / 2013-4-16 / USD 29.95

Two Scoops of Django: Best Practices For Django 1.5 is chock-full of material that will help you with your Django projects. We'll introduce you to various tips, tricks, patterns, code snippets, and......一起来看看 《Two Scoops of Django》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换