Latest 1.0.1
Homepage https://github.com/sbrighiu/BottomKeyboardConstraint
License MIT
Platforms ios 11.0
Authors

CI Status
Version
License
Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

BottomKeyboardConstraint is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'BottomKeyboardConstraint'

Description

BottomKeyboardConstraint is a library that makes it easy and transparent to deal with keyboard events, animations and dismissal.

It is always recommended pairing the view controllers using a keyboard with an UIScrollView. This library uses the bottom keyboard set by you to maintain the distance set from the bottom to the UI element selected.

Just set the bottomKeyboardConstraint to connect the bottom layout guide / top superview bottom and the bottom most element defined, and the library will do the rest.

The whole library is set up as an extension of NSLayoutConstraint and uses a simple registerAsBottomKeyboardConstraint(in: <KeyboardDelegate object>) to activate.

The KeyboardDelegate is defined as:

public protocol KeyboardDelegate {
    var bottomKeyboardConstraint: NSLayoutConstraint? { get set }

    var view: UIView! { get set }

    // Optional methods 
    func keyboardUpdated(withState state: KeyboardState)
    func keyboardShouldDismissAtTap() -> Bool // Default implementation returns true
}

Optionally, you can define keyboardUpdated(withState state: KeyboardState) method and listen for the following keyboard events:

public enum KeyboardState {
    case willUpdateHeight(from: CGFloat, to: CGFloat)
    case didShow
    case didSwitch
    case willHide
    case didHide
}

Usage

//.. Import the library
import BottomKeyboardConstraint

//.. Make UIViewController or any other object a delegate for the keyboard
class ViewController: UIViewController, KeyboardDelegate {

//.. Declare a bottomKeyboardConstraint variable either as a @IBOutlet or create it in code and return it
@IBOutlet weak var bottomKeyboardConstraint: NSLayoutConstraint?
    override func viewDidLoad() {
        super.viewDidLoad()

        //.. Setup the bottomKeyboardConstraint as the keyboard constraint to have it update as the keyboard shows/updates/hides.
        bottomKeyboardConstraint?.registerAsBottomKeyboardConstraint(in: self)
}

//.. Optionally you can also subscribe to the keyboard events
func keyboardUpdated(withState state: KeyboardState) {
    print(state)
}

//.. Optionally you can disable the tap to dismiss functionality when the keyboard is visible
func keyboardShouldDismissAtTap() -> Bool {
    return false
}

Author

Stefan Brighiu, [email protected]

License

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

Latest podspec

{
    "name": "BottomKeyboardConstraint",
    "version": "1.0.1",
    "summary": "BottomKeyboardConstraint is simple library to handle keyboard events.",
    "description": "BottomKeyboardConstraint is a library that supercharges a constraint to update and handle keyboard events.",
    "homepage": "https://github.com/sbrighiu/BottomKeyboardConstraint",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Stefan Brighiu": "[email protected]"
    },
    "source": {
        "git": "https://github.com/sbrighiu/BottomKeyboardConstraint.git",
        "tag": "1.0.1"
    },
    "social_media_url": "https://twitter.com/smbcheeky",
    "platforms": {
        "ios": "11.0"
    },
    "swift_versions": [
        "5.0",
        "5.0"
    ],
    "source_files": "BottomKeyboardConstraint/Classes/**/*",
    "swift_version": "5.0"
}

Pin It on Pinterest

Share This