can't get correct value of keyboard height in iOS8
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Incorrect keyboard height handling can break chat inputs, forms, and bottom action bars. On older iOS versions such as iOS 8, developers often saw confusing values because keyboard frames were reported in screen coordinates and affected by orientation and input mode changes. The fix is to always convert notification frames into local view coordinates and drive layout from constraints instead of hardcoded constants.
Use Keyboard Notifications Correctly
Listen to UIKeyboardWillChangeFrame instead of only show and hide events. Frame-change notifications handle rotation, QuickType bar changes, and third-party keyboard transitions.
This approach works across many keyboard transitions and avoids fixed-height assumptions.
Why Reported Height Looks Wrong
Common reasons developers see wrong values:
- frame is in screen coordinates, not view coordinates
- safe-area insets are not subtracted correctly
- accessory views such as predictive bar change final height
- keyboard is floating or split on iPad
Always calculate overlap with current container bounds instead of trusting raw frame height directly.
Handling iOS 8 Orientation Quirks
On iOS 8, orientation-related coordinate transforms were a frequent source of confusion. If your app supports both portrait and landscape, relying on frame.height alone can be wrong in one orientation.
Use converted frame and overlap math shown above. It remains robust even when orientation changes mid-edit.
Scroll View Content Inset Strategy
For form-heavy screens, update scroll insets instead of moving whole view.
This often provides smoother behavior than translating root view frames.
External Keyboard and Hardware Cases
When a hardware keyboard is connected, software keyboard may not appear. Your layout logic should allow zero overlap and avoid forcing bottom offsets.
Also test with third-party keyboards because height and animation timing can differ from default keyboard behavior.
Testing Matrix
Validate keyboard behavior with:
- portrait and landscape rotation
- predictive text enabled and disabled
- default and third-party keyboards
- iPad split or floating keyboard
- hardware keyboard attached
Most keyboard bugs appear only in one of these states.
Common Pitfalls
- Using only show and hide notifications instead of frame-change notifications.
- Reading keyboard frame without coordinate conversion.
- Animating layout with hardcoded duration instead of notification timing.
- Assuming keyboard height is constant across devices and input modes.
- Forgetting to remove observers in controller lifecycle.
Summary
- Use frame-change keyboard notifications for reliable layout updates.
- Convert keyboard frame to local view coordinates before computing overlap.
- Drive UI changes through constraints or scroll insets, not magic numbers.
- Respect animation duration and curve from notification payload.
- Test across orientation, keyboard types, and accessory bar states.
Migration Note
If you maintain legacy iOS 8 code, isolate keyboard-layout logic in one helper so later platform upgrades can switch to modern safe-area driven approaches with minimal refactoring. Centralized handling also reduces duplicated notification code across multiple form screens.

