Prevent keyboard from covering UITextField/UITextView with only one line of code

KeyboardListener

Prevent keyboard from covering UITextField/UITextView.

Requirements

  • iOS 9.0+
  • Swift 4.0+

Usage

let textView = UITextView(frame: CGRect(x: 20, y: self.view.frame.height-100, width: 200, height: 45))
textView.backgroundColor = UIColor.red
self.view.addSubview(textView)

let textField = UITextField(frame: CGRect(x: 20, y: self.view.frame.height-160, width: 200, height: 45))
textField.backgroundColor = UIColor.yellow
self.view.addSubview(textField)

// add
self.view.addKeyboardListener()

Installation

CocoaPods

To integrate KeyboardListener into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'KeyboardListener'

Manual

  1. Download everything in the KeyboardListener folder;
  2. Add (drag and drop) the source files in KeyboardListener to your project.

License

KeyboardListener is provided under the MIT license. See LICENSE file for details.

GitHub

View Github