Hiding the keyboard with the return button.
class MyViewController: UIViewController, UITextFieldDelegate { @IBOutlet weak var someTextField: UITextField! override func viewDidLoad() { super.viewDidLoad() self.someTextField.delegate = self } func textFieldShouldReturn(textField: UITextField) -> Bool { self.view.endEditing(true) return false } }
Hiding the keyboard when touching somewhere on the screen.
class MyViewController: UIViewController, UITextFieldDelegate { @IBOutlet weak var someTextField: UITextField! override func viewDidLoad() { super.viewDidLoad() self.someTextField.delegate = self } override func touchesBegan(touches: Set, withEvent event: UIEvent?) { someTextField.resignFirstResponder() self.view.endEditing(true) } }