TNKeyboardControlWindow 1.0.7

TNKeyboardControlWindow 1.0.7

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release May 2017

Maintained by Tawa Nicolas.



Summary

TNKeyboardControlWindow is a small utility that helps you integrate keyboard pan-to-dismiss functionality.

Installation

Manual install

Download the folder 'TNKeyboardControlWindow' and add the files to your project.

Integration

In order to handle the keyboard panning accross the whole app, you need to handle it on the UIWindow level. TNKeyboardControlWindow does that for you. You need to #import <TNKeyboardControlWindow.h> in your AppDelegate, and add the following function to the AppDelegate:

Objective-C

-(UIWindow *)window
{
	return [TNKeyboardControlWindow window];
}

Swift

var window: UIWindow? {
	get {
		return TNKeyboardControlWindow.window as UIWindow?
	} set {}
}

This will automatically handle dismissing the keyboard across the whole app by dragging!

In case you have your own custom UIWindow class and you still need to implement this, you can simply subclass TNKeyboardControlWindow instead of UIWindow.

Handling UI

In most of the View Contorllers in your app, you need to update the UI Layout to accomodate to the keyboard displaying on the screen. In order to do that, implement <TNKeyboardListenerProtocol> in your View Controller and add the method

Objective-C

-(void)keyboardDidChangeFrame:(CGRect)frame {
}

Swift

func keyboardDidChangeFrame(_ frame: CGRect) {
	bottomConstraint.constant = 8 + UIScreen.main.bounds.size.height - frame.origin.y
}

You would also need to add your View Controller as a listener to the window by calling

Objective-C

[[TNKeyboardControlWindow window] addKeyboardFrameListener:self];

Swift

TNKeyboardControlWindow.window.addKeyboardFrameListener(self)

Ideally inside your viewDidAppear.

You also need to remove your View Controller when it's no longer displayed by calling

Objective-C

[[TNKeyboardControlWindow window] removeKeyboardFrameListener:self];

Swift

TNKeyboardControlWindow.window.removeKeyboardFrameListener(self)

Optional listener methods

The listener protocol has 4 optional methods that can be implemented in order to avoid having to use NSNotificationCenter to monitor keyboard activity

Objective-C

-(void)keyboardWillStartShowing;
-(void)keyboardDidFinishShowing;

-(void)keyboardWillStartHiding;
-(void)keyboardDidFinishHiding;

Swift

public func keyboardWillStartShowing()
public func keyboardDidFinishShowing()

public func keyboardWillStartHiding()
public func keyboardDidFinishHiding()

And that's it!

A sample project is included with different ViewControllers and different UI components that update with the keyboard.

Notes

Feel free to use 'TNKeyboardControlWindow' in any way you like. An attribution is not required, but is highly appreciated.