Skip to content

Instantly share code, notes, and snippets.

@Arrlindii
Created August 13, 2018 22:10
Show Gist options
  • Select an option

  • Save Arrlindii/dbc61991557e80b8b22f67a2f7463592 to your computer and use it in GitHub Desktop.

Select an option

Save Arrlindii/dbc61991557e80b8b22f67a2f7463592 to your computer and use it in GitHub Desktop.
func bindKeyboardEvents() -> Disposable {
let observable =
Observable.from([
NotificationCenter.default.rx.notification(Notification.Name.UIKeyboardWillShow) .map { notification in
let keyboardFrame = notification.userInfo![UIKeyboardFrameEndUserInfoKey] as! CGRect
let keyboardHeight: CGFloat = keyboardFrame.height
return keyboardHeight
},
NotificationCenter.default.rx.notification(Notification.Name.UIKeyboardWillHide) .map { _ in CGFloat(0) }])
.merge()
.observeOn(MainScheduler.instance)
return observable.subscribe(onNext: { [weak self] keyboardHeight in
self?.contentInset.bottom = keyboardHeight
self?.scrollIndicatorInsets.bottom = keyboardHeight
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment