Last active
July 15, 2019 04:09
-
-
Save simonbromberg/6b5ebb8f322eff84dc0790b8a7cdd192 to your computer and use it in GitHub Desktop.
Keyboard2
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 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