Reactive Keyboard in iOS
Swift Ruby Objective-C


Swift CocoaPods Build Status Carthage compatible

RxKeyboard provides a reactive way of observing keyboard frame changes. Forget about keyboard notifications. It also perfectly works with UIScrollViewKeyboardDismissMode.interactive.

rxkeyboard-message rxkeyboard-textview

Getting Started

RxKeyboard provides two Drivers.

/// An observable keyboard frame.
let frame: Driver<CGRect>

/// An observable visible height of keyboard. Emits keyboard height if the keyboard is visible
/// or `0` if the keyboard is not visible.
let visibleHeight: Driver<CGFloat>

/// Same with `visibleHeight` but only emits values when keyboard is about to show. This is
/// useful when adjusting scroll view content offset.
let willShowVisibleHeight: Driver<CGFloat>

Use RxKeyboard.instance to get singleton instance.


Subscribe RxKeyboard.instance.frame to observe keyboard frame changes.

  .drive(onNext: { frame in

Tips and Tricks

  • πŸ”— I want to adjust UIScrollView's contentInset to fit keyboard height.

      .drive(onNext: { keyboardVisibleHeight in
        scrollView.contentInset.bottom = keyboardVisibleHeight
  • πŸ”— I want to adjust UIScrollView's contentOffset to fit keyboard height.

      .drive(onNext: { keyboardVisibleHeight in
        scrollView.contentInset.offset.y += keyboardVisibleHeight
  • πŸ”— I want to make UIToolbar move along with the keyboard in an interactive dismiss mode. (Just like the wonderful GIF above!)

    If you're not using Auto Layout:

      .drive(onNext: { keyboardVisibleHeight in
        toolbar.frame.origin.y = self.view.height - toolbar.frame.height - keyboardVisibleHeight

    If you're using Auto Layout, you have to capture the toolbar's bottom constraint and set constant to keyboard visible height.

      .drive(onNext: { keyboardVisibleHeight in
        toolbarBottomConstraint.constant = -1 * keyboardVisibleHeight

    Note: In real world, you should use setNeedsLayout() and layoutIfNeeded() with animation block. See the example project for example.

  • Anything else? Please open an issue or make a Pull Request.



  • Swift 3
  • iOS 8+


  • Using CocoaPods:

    pod 'RxKeyboard', '~> 0.4'
  • Using Carthage:

    github "devxoul/RxKeyboard" ~> 0.4


RxKeyboard is under MIT license.