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
From the course: iOS 14 Development Essential Training
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Choosing between SwiftUI and storyboards3m 4s
-
Drag-and-drop user interface creation with storyboards4m 31s
-
Change a label's text at runtime5m 4s
-
Handling a button press5m 14s
-
Using text gathered from text fields5m 33s
-
Showing the keyboards1m 44s
-
Dismissing the keyboard2m 49s
-
Working with pins4m 27s
-
Troubleshoot common UI problems6m 21s
-
Challenge: Storyboards1m 58s
-
Solution: Storyboards3m 59s
-
-
-
-
-