Bird
0
0

You want to move the view up when the keyboard appears and move it back down when it hides. Which approach correctly handles this in Swift?

hard📝 navigation Q15 of 15
iOS Swift - User Input and Forms
You want to move the view up when the keyboard appears and move it back down when it hides. Which approach correctly handles this in Swift?
AListen to keyboardWillShow and keyboardWillHide notifications, adjust view frame accordingly
BOnly listen to keyboardDidShow notification and adjust view frame
CUse a timer to check keyboard height every second and move view
DChange the keyboard type to avoid covering the view
Step-by-Step Solution
Solution:
  1. Step 1: Understand keyboard notifications

    keyboardWillShow and keyboardWillHide notify before keyboard appears/disappears, allowing smooth UI changes.
  2. Step 2: Adjust view frame on both notifications

    Adjusting view frame up on show and back down on hide keeps UI consistent and responsive.
  3. Step 3: Evaluate other options

    Listening only to keyboardDidShow is late; timer wastes resources; changing keyboard type doesn't solve overlap.
  4. Final Answer:

    Listen to keyboardWillShow and keyboardWillHide notifications, adjust view frame accordingly -> Option A
  5. Quick Check:

    Use willShow and willHide notifications for UI moves [OK]
Quick Trick: Use willShow and willHide notifications to move views [OK]
Common Mistakes:
  • Using only keyboardDidShow notification
  • Polling keyboard height with timer
  • Trying to change keyboard type to fix layout

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes