Prabhakar Patil Prabhakar Patil - 1 year ago 80
Swift Question

Hiding The Keyboard in ios Swift

I want to hide the soft-keyboard whenever the user taps on the screen other than the textfield.

Answer Source

You can do something like,

override func viewDidLoad() {

//Looks for single or multiple taps. 
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "dismissKeyboard")

//Calls this function when the tap is recognized.
func dismissKeyboard() {
//Causes the view (or one of its embedded text fields) to resign the first responder status.

Hope this will help :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download