0

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?

Ploostic
  • 7
  • 1
  • 2
  • Possible duplicate of [hide keyboard for text field in swift programming language](http://stackoverflow.com/questions/24908966/hide-keyboard-for-text-field-in-swift-programming-language) – Adam S Jun 16 '16 at 17:37

2 Answers2

0

You have to use resignFirstResponder() property of the text field.

Mtoklitz113
  • 3,828
  • 3
  • 21
  • 40
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