Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Jason Gong
4,537 PointsAdding similar code to multiple ViewControllers
I am trying to make the keyboard disappear on tap outside of the UITextField and also trying to shift up the frame when the keyboard appears. This will probably be done on at least 4 or 5 viewcontrollers. I was wondering if there's a way other than pasting the code in each separate viewcontroller as it seems kind of redundant to do so.
1 Answer
Stone Preston
42,016 Pointsuse TPKeyboardAvoiding. Its very simple to use and implement keyboard avoiding and is much easier than having to write all the code yourself. It is a very popular library and all you have to do is add a scroll view to your view controller, subclass TPkeyboardAvoiding scroll view and add some auto layout constraints
This video shows you how to set keyboard avoiding up using TPKeyboardAvoiding. Its using iOS 7 and objective C, but its almost all storyboard stuff so it translates well into Xcode 6.
if you are using swift you will need to use a bridging header to import TPKeyboardAvoiding