Keyboarding 1.2.0

Keyboarding 1.2.0

Maintained by Mikkel Ulstrup.



  • By
  • Menly ApS


CI Status Swift 4.2 Twitter

๐Ÿคจ What is this?

A simple keyboard helper for handling the appearance of the iOS keyboard.

๐Ÿ“ Requirements

Name Minimum version
Swift 4.2
iOS 11.0

๐Ÿ“ฒ Installation

Carthage

Add the following to your Cartfile:

github "menly/keyboarding-ios"

CocoaPods

Add the following to your podfile:

pod 'Keyboarding'

โŒจ๏ธ Usage

Import the framework:

import Keyboarding

Create an instance of our keyboard helper in your controller:

private let keyboarding = Keyboarding()

Assign your controller to the delegate, and be able to respond to changes in the keyboard:

keyboarding.delegate = self

This will allow you to implement the 2 required functions that are called when the keyboard visability changes:

private func keyboardDidAppear(_ info: KeyboardInfo?, _ error: Error?) {
    if let error = error {
        /// Handle error.

    } else if let info = info {
        info.animateWithKeyboard({ [weak self] in
            self?.bottomAnchor?.constant = -info.endFrame.height
            self?.view.layoutIfNeeded()
        }, completion: nil)
    }
}

private func keyboardDidDisappear(_ info: KeyboardInfo?, _ error: Error?) {
    if let error = error {
        /// Handle error.

    } else if let info = info {
        info.animateWithKeyboard({ [weak self] in
            self?.bottomAnchor?.constant = 0
            self?.view.layoutIfNeeded()
        }, completion: nil)
    }
}

Make sure you add the delegate to the keyboard helper in the viewDidLoad or init method. (just make sure it's added before the keyboard notification fires): This way it's easy to handle the keyboard in your iOS app.

In the body of the functions above, you can do as you please with the KeyboardInfo struct. In this example, I have used the helper method (animateWithKeyboard) on the class, that allows you to use the same animations as the keyboard, but you can also just access the properties of the KeyboardInfo struct and handle the animations yourself.

๐Ÿ‘‹ Get in touch!

Get in touch with us! Send us an email, say hi on twitter (@menlyhq) or check out our website.

๐Ÿ“„ License

See the license file for more information.

The names and logos for Menly and their products are trademarks of Menly ApS.

Copyright (c) Menly ApS 2016-present.