Skip to content

Instantly share code, notes, and snippets.

@simonbromberg
Last active July 15, 2019 03:40
Show Gist options
  • Save simonbromberg/1da87afca3c527b3e9eb10070cbfaa36 to your computer and use it in GitHub Desktop.
Save simonbromberg/1da87afca3c527b3e9eb10070cbfaa36 to your computer and use it in GitHub Desktop.
Keyboard
func registerKeyboardNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillChangeFrame(_:)), name: NSNotification.Name.UIKeyboardWillChangeFrame, object: nil)
}
@objc func keyboardWillShow(_ notification: Foundation.Notification) {
guard let userInfo = notification.userInfo else {
return
}
let keyboardSize = (userInfo[UIKeyboardFrameEndUserInfoKey] as AnyObject).cgRectValue.size
// Then you update your view based on keyboardSize.height…
}
@objc func keyboardWillHide(_ notification: Foundation.Notification) {
// Revert your view back to the default non-keyboard state…
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment