Coder Social home page Coder Social logo

keyboardcontroller's Introduction

KeyboardController

Version Build Status Swift License Twitter

Simplifies iOS keyboard handling.

License

Source code of this project is available under the standard MIT license. Please see the license file.

Usage

To use KeyboardController, simply initialize it with an array of UITextField objects.

let fields = [field1!, field2!, field3!, field4!, field5!]
self.controller = KeyboardController(fields: fields)

You can interact with KeyboardController directly via the following methods:

func moveToNextField()
func moveToPreviousField()
func closeKeyboard()

KeyboardController, depending on a returnKeyType property of an UITextField instance, will:

  • UIReturnKeyNext - move to next text field
  • UIReturnKeyDone - close keyboard

KeyboardControllerDelegate

You could also take advantage of delegation methods:

func controllerDidHideKeyboard(controller: KeyboardController)
func controllerDidShowKeyboard(controller: KeyboardController)
func controllerWillHideKeyboard(controller: KeyboardController)
func controllerWillShowKeyboard(controller: KeyboardController)

by setting a delegate property of a KeyboardController:

self.keyboardController.delegate = self;

UITextFieldDelegate

There is also an option of setting a textFieldDelegate property of all textFields that are under control of KeyboardController:

self.keyboardController.textFieldDelegate = self;

This could be particulary useful if you would like to add individual behaviour to UITextFields objects.

func textFieldDidBeginEditing(_ textField: UITextField) {
    if (textField == self.field4) { self.moveViewBy(-10) }
    if (textField == self.field5) { self.moveViewBy(-200) }
}

func textFieldDidEndEditing(_ textField: UITextField) {
    if (textField == self.field4) { self.moveViewBy(10) }
    if (textField == self.field5) { self.moveViewBy(200) }
}

Contributing

  1. Fork it.
  2. Create your feature branch (git checkout -b new-feature).
  3. Commit your changes (git commit -am 'Added new-feature').
  4. Push to the branch (git push origin new-feature).
  5. Create new Pull Request.

keyboardcontroller's People

Contributors

michalkonturek avatar mstralka 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.