How do I dismiss the iOS keyboard?

后端 未结 16 1150
情书的邮戳
情书的邮戳 2020-11-29 20:00

I have a UITextfield that i\'d like to dismiss the keyboard for. I can\'t seem to make the keyboard go away no matter what code i use.

16条回答
  •  甜味超标
    2020-11-29 20:30

    For Swift 3

    You can hide the keyboard like this:

    textField.resignFirstResponder()
    

    If you want to hide the keyboard when the user press the "intro" button, you have to implement the following UITextFieldDelegate method:

    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
    
        textField.resignFirstResponder()
    
        return true
    }
    

提交回复
热议问题