Created
February 26, 2018 01:47
-
-
Save jeffypooo/2597d5911d6d540f0ce6b5504b86bf5d to your computer and use it in GitHub Desktop.
Keyboard handling extension for UIViewController
This file contains 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
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