Skip to content

Instantly share code, notes, and snippets.

@simonbromberg
Last active July 15, 2019 04:09
Show Gist options
  • Save simonbromberg/6b5ebb8f322eff84dc0790b8a7cdd192 to your computer and use it in GitHub Desktop.
Save simonbromberg/6b5ebb8f322eff84dc0790b8a7cdd192 to your computer and use it in GitHub Desktop.
Keyboard2
func registerKeyboardNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillChangeFrame(_:)), name: NSNotification.Name.UIKeyboardWillChangeFrame, object: nil)
}
@objc func keyboardWillChangeFrame(_ notification: Foundation.Notification) {
guard let userInfo = notification.userInfo else {
return
}
let offset = UIScreen.main.bounds.height - (userInfo[UIKeyboardFrameEndUserInfoKey] as AnyObject).cgRectValue.minY
// Update your view…
}
// Oh and don't forget:
func deregisterKeyboardNotifications() {
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillChangeFrame, object: nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment