From the course: iOS 14 Development Essential Training

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Dismissing the keyboard

Dismissing the keyboard

From the course: iOS 14 Development Essential Training

Start my 1-month free trial

Dismissing the keyboard

- [Instructor] In the same way that you can show the keyboard and highlight a text field when you want, you can actually dismiss the keyboard, and hide, and de-select the keyboard when you want as well. So let's take a look at how to do that. One of the times you might want to dismiss the keyboard is when the user taps elsewhere on the screen. So when they do that, you can assume that they don't want to edit that text field anymore. So to handle capturing when the user taps away from the text field, all you need to do is handle a method called touchesBegan. So right below where we have buttonPressed, between that closed curly brace and the closed curly brace of UIViewController, which starts up here, type touchesBegan, and you'll see it highlighted in the code hinting as you type it out. Then, simply press Return. And then, you can hit Backspace to remove that highlighted code in there. Now, touchesBegan is similar to this…

Contents