Swift - 如何在文本字段外部点击后关闭数字键盘 [英] Swift - How to dismiss number keyboard after tapping outside of the textfield
本文介绍了Swift - 如何在文本字段外部点击后关闭数字键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当点击键盘外部时,如何从UITextField中解除键盘。我试过 resignFirstResponder()
,它只在输入一个数字后退出。我也试过 textField.inputView = UIView.frame(frame:CGRectZero)
。我已经看到了很多Obj-C的问题,但是我需要Swift等价物,因为我没有Objective-C的编程经验
How would you dismiss the keyboard from the UITextField when tapping outside of the keyboard. I have tried resignFirstResponder()
and it only exits after typing one number. I have also tried textField.inputView = UIView.frame(frame: CGRectZero)
. I have seen many Obj-C verisons of what I'm asking but I need the Swift equivalent because I have no programming experience in Objective-C
谢谢你的时间和耐心。
推荐答案
按返回时也可以使用此方法关闭键盘
You could also use this method to dismiss the keyboard when pressing 'Return'
func textFieldShouldReturn(textField: UITextField!) -> Bool {
self.view.endEditing(true);
return false;
}
确保设置代理
这篇关于Swift - 如何在文本字段外部点击后关闭数字键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文