Skip to content
An elegant Keyboard library for iOS. simple, lightweight and standalone no sub-dependencies required
Swift Ruby Objective-C
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
CommonKeyboard.xcodeproj Update version to 1.0.3 Sep 10, 2019
Examples Completed project with examples Sep 9, 2019
Sources Update version to 1.0.4 Sep 12, 2019
.gitignore Initial commit Sep 6, 2019
CommonKeyboard.podspec Update version to 1.0.4 Sep 12, 2019 Correct Sep 12, 2019


An elegant Keyboard library for iOS. simple, lightweight and standalone no sub-dependencies required

Swift Swift

CommonKeyboard CommonKeyboardObserver



Add the following to your Podfile

pod 'CommonKeyboard'


Add the following to your Cartfile

github "kaweerutk/CommonKeyboard"


In AppDelegate.swift, just import CommonKeyboard framework and enable CommonKeyboard.

import CommonKeyboard

class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        // Just enable a single line of code
        CommonKeyboard.shared.enabled = true

        return true

CommonKeyboard will automatically scroll to the input view when the cursor focused and tapping on a space to dismiss keyboard. This working with UIScrollView and all inheritance classes including UITableView and UICollectionView (Note: This does not support UITableViewController because it will handle by itself)

Adjust an offset between keyboard and input view by set keyboardOffset the default value is 10, Or ignore common keyboard by giving ignoredCommonKeyboard a true value.

 textField.keyboardOffset = 20
 textField.ignoredCommonKeyboard = true

 textView.keyboardOffset = 2
 textView.ignoredCommonKeyboard = false


You can subscribe CommonKeyboardObserver to get keyboard notification info.

import CommonKeyboard

class ExampleChatViewController: UIViewController {

    @IBOutlet var tableView: UITableView!
    @IBOutlet var bottomConstraint: NSLayoutConstraint!
    let keyboardObserver = CommonKeyboardObserver()

    override func viewDidLoad() {
        // drag down to dismiss keyboard
        tableView.keyboardDismissMode = .interactive

        keyboardObserver.subscribe(events: [.willChangeFrame, .dragDown]) { [weak self] (info) in
            guard let weakSelf = self else { return }
            var bottom = 0
            if info.isShowing {
                bottom = -info.visibleHeight
                if #available(iOS 11, *) {
                    bottom += weakSelf.view.safeAreaInsets.bottom
            UIView.animate(info, animations: { [weak self] in
                self?.bottomConstraint.constant = bottom


All events

public enum CommonKeyboardObserverEvent {
    case willShow
    case didShow
    case willHide
    case didHide
    case willChangeFrame
    case didChangeFrame
    case dragDown // scroll.keyboardDismissMode = .interactive

Sometimes there are many UIScrollView containers in UI Stack View and the CommonKeyboard cannot find the right one you can implement CommonKeyboardContainerProtocol and return specific container

extension ExampleChatViewController: CommonKeyboardContainerProtocol {
    var scrollViewContainer: UIScrollView {
        return tableView


 // dismiss keyboard

 // get current UIResponder
 let responder = CommonKeyboard.shared.currentResponder


  • iOS9 or later
  • Swift 4.2 or later


If you have any question or issue please create an issue!


CommonKeyboard is released under the MIT License.

You can’t perform that action at this time.