Last active
July 15, 2019 03:40
-
-
Save simonbromberg/1da87afca3c527b3e9eb10070cbfaa36 to your computer and use it in GitHub Desktop.
Keyboard
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(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