美文网首页Swift
学习笔记:swift——收回textfield键盘

学习笔记:swift——收回textfield键盘

作者: 独居焚香 | 来源:发表于2015-12-09 11:33 被阅读2041次

首先,引用UITextFieldDelegate类

override func viewDidLoad() {
        super.viewDidLoad()
text.delegate = self
}

//点击return 收回键盘
   func textFieldShouldReturn(textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true
    }
//点击其他地方  收回键盘
    override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
        text.resignFirstResponder()
    }

相关文章

网友评论

    本文标题:学习笔记:swift——收回textfield键盘

    本文链接:https://www.haomeiwen.com/subject/srnehttx.html