Skip to content

Instantly share code, notes, and snippets.

@M0rtyMerr
Last active June 2, 2019 18:13
Show Gist options
  • Save M0rtyMerr/6d885a4fb4d6acabcc052070917e33be to your computer and use it in GitHub Desktop.
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
// 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