Challenge - 5 Problems
Keyboard Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
Keyboard Avoidance Behavior
What will happen when the keyboard appears in this SwiftUI view?
iOS Swift
struct ContentView: View {
@State private var text = ""
var body: some View {
VStack {
TextField("Enter text", text: $text)
.padding()
Spacer()
}
.padding()
}
}Attempts:
2 left
💡 Hint
Think about default SwiftUI behavior without extra modifiers.
✗ Incorrect
By default, SwiftUI does not automatically move views when the keyboard appears. Without extra code, the keyboard covers the TextField.
❓ lifecycle
intermediate1:30remaining
Keyboard Notification Handling
Which notification should you observe to detect when the keyboard will show in UIKit?
Attempts:
2 left
💡 Hint
You want to know just before the keyboard appears.
✗ Incorrect
UIKeyboardWillShowNotification is sent just before the keyboard appears, allowing you to adjust UI accordingly.
🔧 Debug
advanced2:30remaining
Fixing Keyboard Overlap Bug
Why does this UIKit code fail to move the view up when the keyboard appears?
iOS Swift
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil) @objc func keyboardWillShow(notification: NSNotification) { let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue self.view.frame.origin.y = -keyboardSize!.height }
Attempts:
2 left
💡 Hint
Think about what happens when the keyboard disappears.
✗ Incorrect
The code moves the view up but does not move it back down when the keyboard hides, so the view stays shifted.
advanced
2:00remaining
Keyboard and Navigation Controller Interaction
In a UINavigationController stack, what is the best way to ensure the keyboard does not cover input fields on pushed view controllers?
Attempts:
2 left
💡 Hint
Think about scroll views and their built-in support for content adjustment.
✗ Incorrect
Adjusting contentInset and scrollIndicatorInsets of scroll views is the standard way to keep inputs visible when keyboard appears.
🧠 Conceptual
expert3:00remaining
SwiftUI Keyboard Management Best Practice
Which approach is recommended to handle keyboard avoidance in SwiftUI for complex forms?
Attempts:
2 left
💡 Hint
Think about combining SwiftUI layout tools with keyboard info.
✗ Incorrect
Using GeometryReader with keyboard height notifications allows dynamic padding adjustments to keep inputs visible in SwiftUI.