PrettyKeyboardHelper
A safe helper for keyboard notifications written in Swift.
Installation
CocoaPods
KeyboardWrapper is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'PrettyKeyboardHelper'
Usage
- Import module
import PrettyKeyboardHelper
- Create
PrettyKeyboardHelper
instance
private var prettyKeyboardHelper: PrettyKeyboardHelper?
override func viewDidLoad() {
super.viewDidLoad()
prettyKeyboardHelper = PrettyKeyboardHelper(delegate: self)
}
- Implement
PrettyKeyboardHelperDelegate
Simple example
extension ViewController: PrettyKeyboardHelperDelegate {
func keyboardWillChange(_ keyboardInfo: PrettyKeyboardInfo) {
bottomLayoutConstraint?.constant = keyboardInfo.estimatedKeyboardHeight
//animating
UIView.animate(withDuration: keyboardInfo.duration, delay: 0, options: keyboardInfo.animationOptions, animations: {
self.view.layoutIfNeeded()
}, completion: nil)
}
}
Resize bottom constraint
extension ViewController: PrettyKeyboardHelperDelegate {
func keyboardWillChange(_ keyboardInfo: PrettyKeyboardInfo) {
bottomLayoutConstraint?.updateConstant(keyboardInfo: keyboardInfo)
}
}
Resize bottom constraint with UITabBar
extension ViewController: PrettyKeyboardHelperDelegate {
func keyboardWillChange(_ keyboardInfo: PrettyKeyboardInfo) {
bottomLayoutConstraint?.updateConstant(with: keyboardInfo)
}
}
Change insets for UIScrollView
extension ViewController: PrettyKeyboardHelperDelegate {
func keyboardWillChange(_ keyboardInfo: PrettyKeyboardInfo) {
tableView?.updateBottomInset(with: keyboardInfo)
}
}
Change insets for UIScrollView with UITabBar
extension ViewController: PrettyKeyboardHelperDelegate {
func keyboardWillChange(_ keyboardInfo: PrettyKeyboardInfo) {
tableView?.updateBottomInset(with: keyboardInfo)
}
}
Requirements
- iOS 11.0 or higher
- Xcode 11.0 (swift 5) or higher
License
PrettyKeyboardHelper is available under the MIT license. See the LICENSE file for more info.