KeyboardNotification protocol helps to get all the Keyboard events like Show / Hide / Frame Changes along with keyboard frame and size.
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapodsTo integrate KeyboardNotification into your Xcode project using CocoaPods, specify it in your Podfile:
target '<Your Target Name>' do
pod 'KeyboardNotification'
endThen, run the following command:
$ pod installIt is very simple and easy to use. Just adopt KeyboardNotification protocol to your Controller class or any class. Register your class for desire Notification.Keyboard type.
class ViewController: UIViewController, KeyboardNotification {
...
override func viewDidLoad(_ animated: Bool) {
super.viewDidLoad(animated)
// Register Keboard notification with inline closure
registerKeyboardNotification(.willShow) { note _ in
// Get notifcation when Keyboard will appears
}
// register Keyboard notification with inline function
registerKeyboardNotification(.willHide, handler: willHideKeyboard)
}
func willHideKeyboard(_ note: Notification) {
// Write your code while hiding keyboard
....
// Access keyboard frame
let frame = note.keyboardFrame
}
}For more details check for sample project.