What is the main purpose of keyboard management in iOS apps?
To ensure that the keyboard does not cover important UI elements like text fields, allowing users to see what they are typing and interact smoothly.
Click to reveal answer
beginner
Which notification is commonly observed to detect when the keyboard appears or disappears?
UIKeyboardWillShowNotification and UIKeyboardWillHideNotification are used to detect when the keyboard appears and disappears, respectively.
Click to reveal answer
intermediate
How can you adjust a UIScrollView when the keyboard appears?
By changing the scroll view's contentInset and scrollIndicatorInsets to add space at the bottom equal to the keyboard height, so content is not hidden.
Click to reveal answer
beginner
What method should you call to dismiss the keyboard when the user taps outside a text field?
Call view.endEditing(true) to dismiss the keyboard by resigning the first responder status from the active text field.
Click to reveal answer
intermediate
Why is it important to remove keyboard notification observers?
To prevent memory leaks and unexpected behavior, you should remove observers when they are no longer needed, typically in deinit or viewWillDisappear.
Click to reveal answer
Which notification tells you the keyboard is about to appear?
AUIKeyboardDidHideNotification
BUIKeyboardDidShowNotification
CUIKeyboardWillShowNotification
DUIKeyboardWillHideNotification
✗ Incorrect
UIKeyboardWillShowNotification is sent just before the keyboard appears, allowing you to adjust your UI.
What property of UIScrollView do you adjust to prevent the keyboard from covering content?
AisHidden
BbackgroundColor
Calpha
DcontentInset
✗ Incorrect
Adjusting contentInset adds padding inside the scroll view so content is visible above the keyboard.
How do you dismiss the keyboard programmatically in Swift?
Aview.endEditing(true)
Bkeyboard.dismiss()
CtextField.hideKeyboard()
DUIApplication.shared.dismissKeyboard()
✗ Incorrect
Calling view.endEditing(true) tells the view to resign first responder status and hide the keyboard.
When should you remove keyboard notification observers?
ANever, they are removed automatically
BIn deinit or viewWillDisappear
COnly when the app goes to background
DAfter every keyboard appearance
✗ Incorrect
Removing observers in deinit or viewWillDisappear prevents memory leaks and unexpected notifications.
Which UIKit key helps you detect keyboard frame changes?
AUIKeyboardFrameEndUserInfoKey
BUITextField
CNSNotificationCenter
DUIResponder
✗ Incorrect
UIKeyboardFrameEndUserInfoKey provides the keyboard's frame in the notification's userInfo dictionary.
Explain how to adjust your app's UI when the keyboard appears to keep text fields visible.
Think about listening for keyboard events and changing scroll view padding.
You got /4 concepts.
Describe why and how you should remove keyboard notification observers in your iOS app.
Consider app lifecycle and resource management.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of managing the keyboard in an iOS app?
easy
A. To disable typing in text fields
B. To keep input fields visible when the keyboard appears
C. To change the keyboard color
D. To automatically save user input
Solution
Step 1: Understand keyboard impact on UI
The keyboard can cover input fields, making them hard to see or use.
Step 2: Purpose of keyboard management
Managing the keyboard ensures input fields stay visible and accessible when typing.
Final Answer:
To keep input fields visible when the keyboard appears -> Option B
Quick Check:
Keyboard management = keep inputs visible [OK]
Hint: Keyboard management keeps inputs visible when typing [OK]
Common Mistakes:
Thinking keyboard management changes keyboard color
Believing it disables typing
Assuming it auto-saves input
2. Which Swift method is used to dismiss the keyboard when tapping outside a UITextField?
easy
A. textField.resignFirstResponder()
B. textField.becomeFirstResponder()
C. textField.showKeyboard()
D. textField.hideKeyboard()
Solution
Step 1: Identify method to dismiss keyboard
Calling resignFirstResponder() on a UITextField tells it to stop being active, hiding the keyboard.
Step 2: Check other options
becomeFirstResponder() shows keyboard; showKeyboard() and hideKeyboard() do not exist in UIKit.
Final Answer:
textField.resignFirstResponder() -> Option A
Quick Check:
Dismiss keyboard = resignFirstResponder() [OK]
Hint: Use resignFirstResponder() to hide keyboard [OK]
Common Mistakes:
Using becomeFirstResponder() which shows keyboard
Trying non-existent methods like hideKeyboard()
Not calling any method to dismiss keyboard
3. Given this Swift code snippet, what happens when the keyboard appears?