Last active
June 2, 2019 18:13
-
-
Save M0rtyMerr/6d885a4fb4d6acabcc052070917e33be to your computer and use it in GitHub Desktop.
Old plain way of getting keyboard height vs RxKeyboard framework. Rx frameworks can be found here - https://github.com/RxSwiftCommunity/RxKeyboard
This file contains 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
// native way | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
NotificationCenter.default.addObserver( | |
self, | |
selector: #selector(keyboardChangedFrame), | |
name: UIResponder.keyboardDidChangeFrameNotification, | |
object: nil | |
) | |
} | |
@objc func keyboardChangedFrame(notification: Notification) { | |
guard let keyboardFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue else { return } | |
let keyboardHeight = keyboardFrame.cgRectValue.height | |
scrollView.contentInset.bottom = keyboardHeight | |
} | |
//____________________// | |
// RxKeyboard | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
RxKeyboard.instance.visibleHeight | |
.drive(onNext: { [unowned self] in self.tableView.contentInset.bottom = $0 }) | |
.disposed(by: disposeBag) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment