Swiftpack.co -  RxSwiftCommunity/RxKeyboard as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Reactive Keyboard in iOS
.package(url: "https://github.com/RxSwiftCommunity/RxKeyboard.git", from: "2.0.0")


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
  .disposed(by: disposeBag)

Tips and Tricks

  • 🔗 I want to adjust UIScrollView's contentInset to fit keyboard height.

      .drive(onNext: { [scrollView] keyboardVisibleHeight in
        scrollView.contentInset.bottom = keyboardVisibleHeight
      .disposed(by: disposeBag)
  • 🔗 I want to adjust UIScrollView's contentOffset to fit keyboard height.

      .drive(onNext: { [scrollView] keyboardVisibleHeight in
        scrollView.contentOffset.y += keyboardVisibleHeight
      .disposed(by: disposeBag)
  • 🔗 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: { [toolbar, view] keyboardVisibleHeight in
        toolbar.frame.origin.y = view.frame.height - toolbar.frame.height - keyboardVisibleHeight
      .disposed(by: disposeBag)

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

      .drive(onNext: { [toolbarBottomConstraint] keyboardVisibleHeight in
        toolbarBottomConstraint.constant = -1 * keyboardVisibleHeight
      .disposed(by: disposeBag)

    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 4
  • iOS 8+


In development, RxKeyboard manages dependencies with Swift Package Manager. Use the command below in order to generate a Xcode project file. Note that .xcodeproj file changes are not tracked via git.

$ swift package generate-xcodeproj


  • Using CocoaPods:

    pod 'RxKeyboard'
  • Using Carthage:

    binary "https://raw.githubusercontent.com/RxSwiftCommunity/RxKeyboard/master/RxKeyboard.json"

    ⚠️ With Carthage, RxKeyboard only supports binary installation:

    • 0.9.2
      • Xcode 10.1 (10B61)
      • Swift 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)
    • 0.9.0
      • Xcode 10 (10A255)
      • Swift 4.2 (swiftlang-1000.11.37.1 clang-1000.11.45.1)
    • 0.8.2
      • Xcode 9.3 (9E145)
      • Swift 4.1.0 (swiftlang-902.0.48 clang-902.0.37.1)
    • 0.7.1
      • Xcode 9.1 (9B55)
      • Swift 4.0.2 (swiftlang-900.0.69.2 clang-900.0.38)
    • 0.7.0
      • 9.0.1 (9A1004)
      • Swift 4.0 (swiftlang-900.0.65.2 clang-900.0.37)


RxKeyboard is under MIT license.


Stars: 1293
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.


Release Notes

RxKeyboard 2.0.0
28 weeks ago

Support RxSwift 6.0

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API