CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.

PrettyKeyboardHelper 2.0.5

PrettyKeyboardHelper 2.0.5

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Jan 2022
SPMSupports SPM

Maintained by Oleksii Naboichenko, Oleksii Naboichenko.




  • By
  • Oleksii Naboichenko

PrettyKeyboardHelper

Platform iOS Swift 5 compatible Cocoapod Build Status License Twitter: @nab0y4enko

A safe helper for keyboard notifications written in Swift.

Demo

Demo

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.