Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Reactive Keyboard in iOS

License

NotificationsYou must be signed in to change notification settings

RxSwiftCommunity/RxKeyboard

Repository files navigation

SwiftCocoaPodsBuild StatusCarthage compatible

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

rxkeyboard-messagerxkeyboard-textview

Getting Started

RxKeyboard provides twoDrivers.

/// An observable keyboard frame.letframe:Driver<CGRect>/// An observable visible height of keyboard. Emits keyboard height if the keyboard is visible/// or `0` if the keyboard is not visible.letvisibleHeight:Driver<CGFloat>/// Same with `visibleHeight` but only emits values when keyboard is about to show. This is/// useful when adjusting scroll view content offset.letwillShowVisibleHeight:Driver<CGFloat>

UseRxKeyboard.instance to get singleton instance.

RxKeyboard.instance

SubscribeRxKeyboard.instance.frame to observe keyboard frame changes.

RxKeyboard.instance.frame.drive(onNext:{ frameinprint(frame)}).disposed(by: disposeBag)

Tips and Tricks

  • 🔗I want to adjustUIScrollView'scontentInset to fit keyboard height.

    RxKeyboard.instance.visibleHeight.drive(onNext:{[scrollView] keyboardVisibleHeightin    scrollView.contentInset.bottom= keyboardVisibleHeight}).disposed(by: disposeBag)
  • 🔗I want to adjustUIScrollView'scontentOffset to fit keyboard height.

    RxKeyboard.instance.willShowVisibleHeight.drive(onNext:{[scrollView] keyboardVisibleHeightin    scrollView.contentOffset.y+= keyboardVisibleHeight}).disposed(by: disposeBag)
  • 🔗I want to makeUIToolbar move along with the keyboard in an interactive dismiss mode. (Just like the wonderful GIF above!)

    If you're not using Auto Layout:

    RxKeyboard.instance.visibleHeight.drive(onNext:{[toolbar, view] keyboardVisibleHeightin    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 setconstant to keyboard visible height.

    RxKeyboard.instance.visibleHeight.drive(onNext:{[toolbarBottomConstraint] keyboardVisibleHeightin    toolbarBottomConstraint.constant=-1* keyboardVisibleHeight}).disposed(by: disposeBag)

    Note: In real world, you should usesetNeedsLayout() andlayoutIfNeeded() with animation block. See theexample project for example.

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

Dependencies

Requirements

  • Swift 5.1
  • iOS 9+

Contributing

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

Installation

  • UsingCocoaPods:

    pod'RxKeyboard'
  • UsingCarthage:

    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)

License

RxKeyboard is under MIT license.

About

Reactive Keyboard in iOS

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors22


[8]ページ先頭

©2009-2025 Movatter.jp