How to dismiss number pad keyboard by tapping anywhere

后端 未结 15 2203
梦如初夏
梦如初夏 2020-12-04 17:53

I\'d like to know the simplest code to dismiss the number pad keyboard when tapping anywhere outside the number pad. It\'s a simple application to input a number inside a te

15条回答
  •  北荒
    北荒 (楼主)
    2020-12-04 18:15

    For swift 3/4 I like this case:

    1. View Controller is subclass for UITextFieldDelegate
    2. In the viewDidLoad function, you have to set yourPhonePadField.delegate = self
    3. And override this function:

      override func touchesBegan(_ touches: Set, with event: UIEvent?) {
         self.view.endEditing(true) 
      }
      

提交回复
热议问题