Skip to content

Instantly share code, notes, and snippets.

@Lancewer
Created December 23, 2017 09:34
Show Gist options
  • Save Lancewer/de025e72e84bf1eb1ca33ebbb91edf9c to your computer and use it in GitHub Desktop.
Save Lancewer/de025e72e84bf1eb1ca33ebbb91edf9c to your computer and use it in GitHub Desktop.
[Close keyboard] close all the keyboard on the screen in iOS #iOS #keyboard #first responder #close
you needn't search and find which inputfield is current first responder, just call the endEditing method in the viewcontroller's view, it will find and resign first responder for itself or textfield inside ot it.
reference on UIView.endEditing:
Causes the view (or one of its embedded text fields) to resign the first responder status.
This method looks at the current view and its subview hierarchy for the text field that is currently the first responder. If it finds one, it asks that text field to resign as first responder. If the force parameter is set to true, the text field is never even asked; it is forced to resign.
//You can drag a tapGestureRecongizer to the very bottom view, and link a IBAction like below to it
@IBAction func closeAllKeyborad(_ sender: Any) {
view.endEditing(true)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment