Question : how to dismiss keyboard swiftui
Answered by : quaint-quail-rblyi6q3wthz
#if canImport(UIKit)
extension View { func hideKeyboard() { UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) }
}
#endif
Source : https://www.hackingwithswift.com/quick-start/swiftui/how-to-dismiss-the-keyboard-for-a-textfield | Last Update : Mon, 12 Oct 20
Question : how to dismiss keyboard in swift
Answered by : encouraging-eland-ol9hnz3fcuoq
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)
}
Source : https://stackoverflow.com/questions/24126678/close-ios-keyboard-by-touching-anywhere-using-swift | Last Update : Sun, 29 Mar 20
Question : swift dismiss keyboard on return
Answered by : mobile-star
extension UIViewController: UITextFieldDelegate{ public func textFieldShouldReturn(_ textField: UITextField) -> Bool { textField.resignFirstResponder() return true; }
}
override func viewDidLoad() { super.viewDidLoad() textField.delegate = self
}
Source : | Last Update : Tue, 10 Mar 20