Created
August 13, 2018 22:10
-
-
Save Arrlindii/dbc61991557e80b8b22f67a2f7463592 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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