IQKeyboardManager: My new favourite iOS library

I rarely get excited about code libraries, but IQKeyboardManager is probably the most useful and useable library I've ever had the pleasure of downloading. Useable in that it requires zero effort to use, no code, no configuration, no API keys. And useful because it solves a problem that has been bugging me since I first got my grubby mitts on the iOS SDK back in 2008.

The Problem

One major hole in Apple's iOS development arsenal is the interplay between keyboard and View. The virtual keyboard will obscure the bottom segment of the screen when it appears, and by default, doesn't have any clear way to be dismissed. Which can cause major problems when you've got a form with even a few text boxes in a 3.5" layout.

Cheesy keyboard annoyance GIF

In the past, I've had to solve this problem by adding the entire form to a scrollview and then finding an article with a code sample to handle the scrolling, or a couple of classes that could be attached to a form that had been set up correctly. Regardless, this always ended up a pain, because I'm the kind of programmer who forgets such trickery and ends up making a scrollview-less form that I quickly realize I need to rebuild completely.

Finding myself in that annoying position again, I took to CocoaPods in search of at least some more easily-reusable scroll handling code, and a faint hope that there would be something to perhaps cleverly add the scrollview for me. What I found was IQKeyboardManager, a perfect solution to this half-decade old pain in the arse.

What it Does

Out of the box, IQKeyboardManager does three main things:
1) Automatically scrolls the screen to keep a selected text field visible
2) Adds a "Done" button to dismiss the keyboard entirely
3) UNEXPECTED BONUS: Provides forward and back buttons to "tab" through text fields

A quick demo:

On their own, these are awesome features and greatly improve the usability of iOS forms, but they'd only be a slight improvement if you needed to add them to all your ViewControllers. This is where IQKeyboardManager hits the ball out of the park, then runs into the parking lot and hits it back in to save the officials a walk.

How to Use It

For the basic features, you just need to link to the library. That's it. If you're using CocoaPods, just add one line to your podfile:

pod 'IQKeyboardManager'

Once you've run pod install, you're good to go. No more faffing with scrollviews. Plus, it's under the MIT licence, so it's good to use in any project you might have. hackiftekhar is my new hero.