Skip to content

Instantly share code, notes, and snippets.

View peterhaldbaek's full-sized avatar

Peter Haldbæk peterhaldbaek

View GitHub Profile
// Add
// private var activeField: UITextField?
// to the view controller
// MARK: - Keyboard animation
extension UIViewController {
// Call this method somewhere in your view controller setup code.
private func registerForKeyboardNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWasShown(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillBeHidden(notification:)), name: UIResponder.keyboardWillHideNotification, object: nil)