Answers for "ensure keyboard dismiss on view dismiss"

2

xcode hide keyboard when touch background storyboard

override func viewDidLoad()
    {
        super.viewDidLoad()
        
        //Hide Keyboard
        let tap = UITapGestureRecognizer(target: self.view, action: #selector(UIView.endEditing))
        view.addGestureRecognizer(tap)
    }
Posted by: Guest on October-08-2020
0

how to dismiss keyboard in swift

override func viewDidLoad() {
    super.viewDidLoad()

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

    //Uncomment the line below if you want the tap not not interfere and cancel other interactions.
    //tap.cancelsTouchesInView = false 

    view.addGestureRecognizer(tap)
}

//Calls this function when the tap is recognized.
@objc func dismissKeyboard() {
    //Causes the view (or one of its embedded text fields) to resign the first responder status.
    view.endEditing(true)
}
Posted by: Guest on March-22-2020

Code answers related to "ensure keyboard dismiss on view dismiss"

Code answers related to "Swift"

Browse Popular Code Answers by Language