Skip to content

Instantly share code, notes, and snippets.

@jeffypooo
Created February 26, 2018 01:47
Show Gist options
  • Save jeffypooo/2597d5911d6d540f0ce6b5504b86bf5d to your computer and use it in GitHub Desktop.
Save jeffypooo/2597d5911d6d540f0ce6b5504b86bf5d to your computer and use it in GitHub Desktop.
Keyboard handling extension for UIViewController
import UIKit
extension UIViewController {
func registerForKeyboardNotifications() {
let center = NotificationCenter.default
center.addObserver(
self,
selector: #selector(keyboardDidShow(_:)),
name: NSNotification.Name.UIKeyboardDidShow,
object: nil
)
center.addObserver(
self,
selector: #selector(keyboardWillShow(_:)),
name: NSNotification.Name.UIKeyboardWillShow,
object: nil
)
center.addObserver(
self,
selector: #selector(keyboardWillHide(_:)),
name: NSNotification.Name.UIKeyboardWillHide,
object: nil
)
}
@objc open func keyboardDidShow(_ notification: NSNotification) {
}
@objc open func keyboardWillShow(_ notification: NSNotification) {
}
@objc open func keyboardWillHide(_ notification: NSNotification) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment