duc-ios / Keyboardy

UIViewController extension for convenient keyboard management.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Keyboardy

Version Carthage Compatible License Platform

Description

Keyboardy extends UIViewController with few simple methods and provides delegate for handling keyboard appearance notifications.

  • Keyboardy is just wrapper on UIKeyboardWillShowNotification and UIKeyboardWillHideNotification notifications.
  • Supports both AutoLayout and frame-based animations.
  • Swift implementation.
  • Without any hacks like method swizzling and magic numbers (ex., curve << 16).

Keyboardy Demo GIF

Usage

  • Import Keyboardy module
import Keyboardy
  • Register for keyboard notifications
override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)

    registerForKeyboardNotifications(self)
}
  • Unregister from keyboard notifications
override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated)

    unregisterFromKeyboardNotifications()
}
  • Implement KeyboardStateDelegate
extension ViewController: KeyboardStateDelegate {

    func keyboardWillTransition(state: KeyboardState) {
        // keyboard will show or hide
    }

    func keyboardTransitionAnimation(state: KeyboardState) {
        switch state {
        case .ActiveWithHeight(let height):
            textFieldContainerBottomConstraint.constant = height
        case .Hidden:
            textFieldContainerBottomConstraint.constant = 0.0
        }

        view.layoutIfNeeded()
    }

    func keyboardDidTransition(state: KeyboardState) {
        // keyboard animation finished
    }
}

Example

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

Requirements

Swift 1.2, iOS 8

Installation via CocoaPods

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

pod "Keyboardy"

Installation via Carthage

Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate Keyboardy into your Xcode project using Carthage, specify it in your Cartfile:

github "podkovyrin/Keyboardy"

Author

Andrew Podkovyrin, podkovyrin@gmail.com

License

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

About

UIViewController extension for convenient keyboard management.

License:MIT License


Languages

Language:Shell 50.0%Language:Swift 43.2%Language:Ruby 3.7%Language:Objective-C 3.1%