I just made a simple app where you type things in four boxes and can randomly select one. After typing in the boxes I need the keyboard to go away so people can see what the result is, but the on-screen keyboard just stays. Is this something I need to change in the files of the app?
Asked
Active
Viewed 40 times
2 Answers
0
You have to use resignFirstResponder()
property of the text field.

Mtoklitz113
- 3,828
- 3
- 21
- 40
-
The problem with that is that i can not assign value of type bool to uitextfield. – Ploostic Jun 16 '16 at 17:37
0
If you want to hide the keyboard when a tap occurred outside the text field,
you can use an UITapGestureRecognizer
.
override func viewDidLoad() {
super.viewDidLoad()
let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(backgroundTapped(_:)))
view.addGestureRecognizer(tapRecognizer)
}
func backgroundTapped(sender: UITapGestureRecognizer) {
view.endEditing(true)
}

Viktor Simkó
- 2,607
- 16
- 22