This library has been deprecated and the repo has been archived.
The code is still here and you can still clone it, however the library will not receive any more updates or support.
KeyboardHelper
No more checking for keyboard notifications and parsing keyboard apperance info manually!
A small (but cool) tool for handling UIKeyboard appearing and disappearing in your view controllers.

📦 Installation
Carthage
github "nodes-ios/KeyboardHelper" ~> 3.0.0
CocoaPods
pod 'KeyboardHelper', '~> 3.0.0'
Older versions
Last versions compatible with lower Swift versions:
Swift 4: ~> 2.0.0
Swift 3: == 1.2.1
Swift 2.3: == 0.10.0
Swift 2.2: == 0.9.4
🔧 Setup
Implement KeyboardHelperDelegate
in your UIViewController.
class ViewController: UIViewController, KeyboardHelperDelegate
Add a KeyboardHelper
private variable, initialize it and set the delegate.
private var keyboardHelper : KeyboardHelper?
func viewDidLoad() {
...
self.keyboardHelper = KeyboardHelper(delegate: self)
...
}
Implement the two methods in the KeyboardHelperDelegate
:
public func keyboardWillAppear(_ info: KeyboardHelper.KeyboardAppearanceInfo)
public func keyboardWillDisappear(_ info: KeyboardHelper.KeyboardAppearanceInfo)
Both methods take as argument a KeyboardAppearanceInfo
object, which is basically a wrapper over the userInfo
dictionary of the UIKeyboardWillShowNotification
and UIKeyboardWillHideNotification
notifications.
One example of implementation for the two delegate methods is:
func keyboardWillAppear(_ info: KeyboardAppearanceInfo) {
UIView.animate(withDuration: TimeInterval(info.animationDuration),
delay: 0,
options: info.animationOptions,
animations: {
let insets = UIEdgeInsetsMake(0, 0, info.endFrame.size.height, 0)
self.scrollView.contentInset = insets
self.scrollView.scrollIndicatorInsets = insets
},
completion: nil)
}
func keyboardWillDisappear(_ info: KeyboardAppearanceInfo) {
UIView.animate(withDuration: TimeInterval(info.animationDuration),
delay: 0,
options: info.animationOptions,
animations: {
let insets = UIEdgeInsetsZero
self.scrollView.contentInset = insets
self.scrollView.scrollIndicatorInsets = insets
},
completion: nil)
}
The KeyboardAppearanceInfo
object has the following properties:
beginFrame
: a CGRect
corresponding to the value for UIKeyboardFrameBeginUserInfoKey
endFrame
: a CGRect
corresponding to the value for UIKeyboardFrameEndUserInfoKey
belongsToCurrentApp
: a Bool
corresponding to the value for UIKeyboardIsLocalUserInfoKey
animationDuration
: a Double
corresponding to the value for UIKeyboardAnimationDurationUserInfoKey
animationCurve
: a UIViewAnimationCurve
corresponding to the value for UIKeyboardAnimationCurveUserInfoKey
animationOptions
: a UIViewAnimationOptions
from the value of UIKeyboardAnimationCurveUserInfoKey
KeyboardAppearanceInfo
also has the convenience method animateAlong:completion:
, which can be used like this:
func keyboardWillAppear(info: KeyboardAppearanceInfo) {
info.animateAlong({ () -> Void in
let insets = UIEdgeInsetsMake(0, 0, info.endFrame.size.height, 0)
self.scrollView.contentInset = insets
self.scrollView.scrollIndicatorInsets = insets
}) { finished in }
to get the same effect as the initial keyboardWillAppear:
implementation example above.
👥 Credits
Made with ❤️ at Nodes.
📄 License
KeyboardHelper is available under the MIT license. See the LICENSE file for more info.
This library has been deprecated and the repo has been archived.
The code is still here and you can still clone it, however the library will not receive any more updates or support.
KeyboardHelper
A small (but cool) tool for handling UIKeyboard appearing and disappearing in your view controllers.
📦 Installation
Carthage
CocoaPods
🔧 Setup
Implement
KeyboardHelperDelegate
in your UIViewController.Add a
KeyboardHelper
private variable, initialize it and set the delegate.Implement the two methods in the
KeyboardHelperDelegate
:Both methods take as argument a
KeyboardAppearanceInfo
object, which is basically a wrapper over theuserInfo
dictionary of theUIKeyboardWillShowNotification
andUIKeyboardWillHideNotification
notifications.One example of implementation for the two delegate methods is:
The
KeyboardAppearanceInfo
object has the following properties:beginFrame
: aCGRect
corresponding to the value forUIKeyboardFrameBeginUserInfoKey
endFrame
: aCGRect
corresponding to the value forUIKeyboardFrameEndUserInfoKey
belongsToCurrentApp
: aBool
corresponding to the value forUIKeyboardIsLocalUserInfoKey
animationDuration
: aDouble
corresponding to the value forUIKeyboardAnimationDurationUserInfoKey
animationCurve
: aUIViewAnimationCurve
corresponding to the value forUIKeyboardAnimationCurveUserInfoKey
animationOptions
: aUIViewAnimationOptions
from the value ofUIKeyboardAnimationCurveUserInfoKey
KeyboardAppearanceInfo
also has the convenience methodanimateAlong:completion:
, which can be used like this:to get the same effect as the initial
keyboardWillAppear:
implementation example above.👥 Credits
Made with ❤️ at Nodes.
📄 License
KeyboardHelper is available under the MIT license. See the LICENSE file for more info.