Latest 1.1.0
Homepage https://github.com/BellAppLab/Keyboard
License MIT
Platforms ios 9.0
Frameworks Foundation
Authors

Keyboard Version License

Platforms
Swift support
CocoaPods Compatible
Carthage compatible
Swift Package Manager compatible
Twitter

Keyboard

Moving the keyboard using autolayout from the bottom of the screen
Moving the keyboard using frame-based layout
Moving the keyboard using autolayout with mutiple text fields inside a view

Never implement NSNotification.Name.UIKeyboardDidShow ever again. Ever.

Yeah, seriously. Handling the keyboard on iOS shouldn’t be painful. But it is.

So instead of doing a whole lot of calculations, or embedding everything in UIScrollViews, import Keyboard and get on with your life.

Specs

  • iOS 9+
  • Swift 4.2+

Usage

Step 1:

Make your view controller conform to the KeyboardChangeHandler protocol:

import Keyboard

class ViewController: UIViewController, KeyboardChangeHandler {

Step 2:

Start handling keyboard notifications:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    becomeKeyboardChangeHandler()
}

override func viewWillDisappear(_ animated: Bool) {
    resignKeyboardChangeHandler()

    super.viewWillDisappear(animated)
}

Step 3:

ctrl + drag to your favorite NSLayoutConstraint:

Interface Builder NSLayoutConstraint

Step 4:

Get on with your life

Goodies

Keyboard comes with a couple of niceties you might enjoy:

  • The Keyboard singleton:
Keyboard.default.isVisible //tells you if the keyboard is currently visible
Keyboard.default.currentFrame //tells you the keyboard's frame
  • Turning keyboard handling off:
class ViewController: UIViewController {
    override func awakeFromNib() {
        super.awakeFromNib()

        //do this if you have set up a bunch of outlets on Interface Builder
        //but don't want Keyboard to work on this view controller for now
        handlesKeyboard = false
    }
}
  • Keyboard margin:
override func viewDidLoad() {
    super.viewDidLoad()

    [...]

    //adds a margin between the keyboard and the currently active text input
    //defaults to 40.0
    keyboardMargin = 60.0
}
  • Finding the currently active text input:
self.view.currentFirstResponder
UIResponder.currentFirstResponder

Notes

  • If the Simulator doesn’t show the keyboard straight away, press cmd+K.

  • You may get the following messages on the console (which don’t affect the library in any way):
    _BSMachError: (os/kern) invalid capability (20)
    _BSMachError: (os/kern) invalid name (15)

Migrating

  • From v0.6.0: Check this out if you’re migrating from version 0.6.0.

Installation

Cocoapods

pod 'Keyboard', '~> 1.1'

Then import Keyboard where needed.

Carthage

github "BellAppLab/Keyboard" ~> 1.1

Then import Keyboard where needed.

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/BellAppLab/Keyboard", from: "1.1")
]

Then import Keyboard where needed.

Git Submodules

cd toYourProjectsFolder
git submodule add -b submodule --name Keyboard https://github.com/BellAppLab/Keyboard.git

Then drag the Keyboard folder into your Xcode project.

Author

Bell App Lab, [email protected]

Credits

Logo image by Gregor Cresnar from The Noun Project

License

Keyboard is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "Keyboard",
    "version": "1.1.0",
    "summary": "Never implement the UIKeyboardDidShow notification ever again. Ever.",
    "screenshots": "https://github.com/BellAppLab/Keyboard/raw/master/Images/keyboard.png",
    "description": "Never implement `NSNotification.Name.UIKeyboardDidShow` ever again. Ever.nnYeah, seriously. Handling the keyboard on iOS shouldn't be painful. But it is.nnSo instead of doing a whole lot of calculations, or embedding everything in `UIScrollView`s, `import Keyboard` and **get on with your life**.",
    "homepage": "https://github.com/BellAppLab/Keyboard",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Bell App Lab": "[email protected]"
    },
    "social_media_url": "https://twitter.com/BellAppLab",
    "platforms": {
        "ios": "9.0"
    },
    "swift_version": "5.0",
    "module_name": "Keyboard",
    "source": {
        "git": "https://github.com/BellAppLab/Keyboard.git",
        "tag": "1.1.0"
    },
    "source_files": "Sources/Keyboard/*.swift",
    "frameworks": "Foundation",
    "ios": {
        "frameworks": "UIKit"
    }
}

Pin It on Pinterest

Share This