0
0
iOS Swiftmobile~20 mins

Keyboard management in iOS Swift - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Keyboard Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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()
  }
}
AThe keyboard will not appear when tapping the TextField.
BThe TextField will disappear when the keyboard appears.
CThe view will automatically move up so the TextField stays visible above the keyboard.
DThe TextField will be covered by the keyboard, making it hard to see what you type.
Attempts:
2 left
💡 Hint
Think about default SwiftUI behavior without extra modifiers.
lifecycle
intermediate
1:30remaining
Keyboard Notification Handling
Which notification should you observe to detect when the keyboard will show in UIKit?
AUIKeyboardWillHideNotification
BUIKeyboardDidHideNotification
CUIKeyboardWillShowNotification
DUIKeyboardDidChangeFrameNotification
Attempts:
2 left
💡 Hint
You want to know just before the keyboard appears.
🔧 Debug
advanced
2: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
}
AThe keyboard size is not unwrapped safely, causing a crash.
BThe view's frame is changed but not reset when keyboard hides, causing layout issues.
CThe notification name is incorrect and never triggers the method.
DThe selector method is not marked @objc, so it won't be called.
Attempts:
2 left
💡 Hint
Think about what happens when the keyboard disappears.
navigation
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?
AAdjust the scroll view's contentInset and scrollIndicatorInsets when keyboard shows and hides.
BManually move the entire navigation controller's view up by keyboard height.
CDisable the keyboard to prevent it from appearing.
DSet the navigation bar to hidden when keyboard appears.
Attempts:
2 left
💡 Hint
Think about scroll views and their built-in support for content adjustment.
🧠 Conceptual
expert
3:00remaining
SwiftUI Keyboard Management Best Practice
Which approach is recommended to handle keyboard avoidance in SwiftUI for complex forms?
AUse GeometryReader and keyboard height notifications to adjust view padding dynamically.
BWrap the entire view in a ScrollView and rely on default behavior without adjustments.
CDisable the keyboard and use custom input views instead.
DUse UIKit UIViewControllerRepresentable to manage keyboard and ignore SwiftUI layout.
Attempts:
2 left
💡 Hint
Think about combining SwiftUI layout tools with keyboard info.