RxKeyboard响应式的 iOS 键盘组件

联合创作 · 2023-09-27 12:30

RxKeyboard 是一个韩国人开发的响应式的 iOS 键盘组件,效果如下图所示:

rxkeyboard-message rxkeyboard-textview

示例代码:

RxKeyboard 提供两种驱动方式:

/// 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>

使用 RxKeyboard.instance 来获取单例实例

RxKeyboard.instance

订阅 RxKeyboard.instance.frame 来侦听键盘帧的变化

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

依赖

要求

  • Swift 4
  • iOS 8+
浏览 14
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报