UITextFields has keyboard as there first responders, as soon you begin editing keyboard shows up.

 

  1. Implement textFieldShouldReturn delegate in the view controller and dismiss each keyboard.
func textFieldShouldReturn(textField: UITextField) -> Bool {
   self.textField1.resignFirstResponder()
   return true
}

 

2.textFieldShouldReturn delegate implementation.

func textFieldShouldReturn(textField: UITextField) -> Bool {
   self.view.endEditing(true)
   return true
}

 

3.Using Extension or ThirdParty

Put bellow extension in you swift file and call this extension in ViewDidLoad or ViewWillAppear.

 

// MARK: ===================== HIDE KEYBOARD ========================== //

extension UIViewController{
 func hideKeyBoard(){
   
     let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(
UIViewController.dismissKeyboard))
     tap.cancelTouchsInView = false
     view.addGestureRecognizer(tap)
    }

func dismissKeyboard() {

     view.endEditing(true)
   }
}

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here