GithubHelp home page GithubHelp logo

jeanbernard / typist Goto Github PK

View Code? Open in Web Editor NEW

This project forked from totocaster/typist

0.0 2.0 0.0 23 KB

Small Swift UIKit keyboard manager for iOS apps.

License: MIT License

Ruby 6.51% Swift 93.49%

typist's Introduction

Typist

Swift Version CocoaPods Compatible Platform

Typist is a small, drop-in Swift UIKit keyboard manager for iOS apps. It helps you manage keyboard's screen presence and behavior without notification center and Objective-C.


Installation

CocoaPods

You can use CocoaPods to install Typist by adding it to your Podfile:

platform :ios, '10.0'
use_frameworks!
pod 'Typist'

Import Typist wherever you plan to listen to keyboard events. Usually in your UIViewController subclasses.

import UIKit
import Typist

Manually

Download and drop Typist.swift in your project.

Usage

Declare what should happen on what event and start() listening to keyboard events. That's it.

let keyboard = Typist.shared

func configureKeyboard() {
	
    keyboard
        .on(event: .didShow) { (options) in
            print("New Keyboard Frame is \(options.endFrame).")
        }
        .on(event: .didHide) { (options) in
            print("It took \(options.animationDuration) seconds to animate keyboard out.")
        }
        .start()

}

Usage of both—singleton, or your own instance of Typist—is considered to be OK depending on what you want to accomplish.

You must call start() for callbacks to be triggered. Calling stop() on instance will stop callbacks from triggering, but callbacks themselves won't be dismissed, thus you can resume event callbacks by calling start() again.

To remove all event callbacks, call clear(). Passing nil instead of closure also removes event callback.

Event Callback Options

Every event callback has a parameter of Typist.KeyboardOptions type. It is an inert/immutable struct which carries all data that keyboard has at the event of happening:

  • belongsToCurrentAppBool that identifies whether the keyboard belongs to the current app. With multitasking on iPad, all visible apps are notified when the keyboard appears and disappears. The value of this key is true for the app that caused the keyboard to appear and false for any other apps.
  • startFrameCGRect that identifies the start frame of the keyboard in screen coordinates. These coordinates do not take into account any rotation factors applied to the window’s contents as a result of interface orientation changes. Thus, you may need to convert the rectangle to window coordinates (using the convertRect:fromWindow: method) or to view coordinates (using the convertRect:fromView: method) before using it.
  • endFrameCGRect that identifies the end frame of the keyboard in screen coordinates. These coordinates do not take into account any rotation factors applied to the window’s contents as a result of interface orientation changes. Thus, you may need to convert the rectangle to window coordinates (using the convertRect:fromWindow: method) or to view coordinates (using the convertRect:fromView: method) before using it.
  • animationCurveUIViewAnimationCurve constant that defines how the keyboard will be animated onto or off the screen.
  • animationDurationDouble that identifies the duration of the animation in seconds.

Events

Following keyboard events are supported:

  • willShow
  • didShow
  • willHide
  • didHide
  • willChangeFrame
  • didChangeFrame

If you declare two closures on same event, only latter will be executed.

License

Typist is released under the MIT license. See LICENSE for details.

typist's People

Contributors

duliodenis avatar jeanbernard avatar totocaster avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.