When I open the application and click in the UITextField it is being instantly dismissed the first time it is clicked. It does not get dismissed after the first time without clicking outside of the view.
I used this answer: Close iOS Keyboard by touching anywhere using Swift for the code to dismiss the textField when an area outside the textField is tapped. Code:
class SettingsViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var textField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
textField.delegate = self
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
view.endEditing(true)
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return false
}