2013-06-17

One Class for One Problem

The keyboard on iOS devices is sometimes a nightmare for a programmer.  Take the UITextField as an example, when a keyboard appears, it will cover most screen area and let the text fields hidden in the back of the soft keyboard. A solution provided by Apple is using the UIScrollView, but there are a lot of mathematical calculation for a programmer. :(

After a while research on the internet, I've found that Michael Tyson has built a drop-in solution for such kind of problems. He packs everything that one needs into a class and puts the sources on GitHub.

If you follow the instruction on the Github, the task with UITextField and Keyboard is easy as a cake!

Usage

For use with UITableViewController classes, drop TPKeyboardAvoidingTableView.m and TPKeyboardAvoidingTableView.h into your project, and make your UITableView a TPKeyboardAvoidingTableView in the xib. If you're not using a xib with your controller, I know of no easy way to make its UITableView a custom class: The path of least resistance is to create a xib for it.
For non-UITableViewControllers, drop the TPKeyboardAvoidingScrollView.m and TPKeyboardAvoidingScrollView.h source files into your project, pop a UIScrollView into your view controller's xib, set the scroll view's class toTPKeyboardAvoidingScrollView, and put all your controls within that scroll view. You can also create it programmatically, without using a xib - just use the TPKeyboardAvoidingScrollView as your top-level view.


Well done, Michael!

via ATasty Pixel

No comments: