Uncovering input fields from iOS Keyboard

Filipe Ximenes
June 10, 2015
<p>One thing new iOS developers notice on their first experiences developing applications is that their interfaces do not adapt to the screen when the keyboard is shown. Because of this, text input fields are hidden by the keyboard if they are to low on the screen. This is a bit annoying and if you have some Android experience you will notice you don't have to deal with this, the OS automatically resizes the interface. The good news is that the solution for this problem is not very complicated.</p><h2 id="cocoapods">CocoaPods</h2><p>Please don’t try to develop your own custom solution for this, there are plenty of open source solutions available so you don’t need to waste time on this. I also expect you to use CocoaPods to install third party libraries. If you don’t know what CocoaPods is or is not already using it, I strongly recommend you to go to <a href="https://cocoapods.org/">https://cocoapods.org/</a> and spend some time exploring it.</p><h2 id="available-libs">Available libs</h2><p>With a quick search you can find many libs addressing this issue. I’ve played with some of then and each one work in it’s own way. Some require you to add <code>import</code>s to your code, others add <code>UIScrollView</code>s to your interface files and some require extra code to be added to the application.</p><h2 id="iqkeyboardmanager">IQKeyboardManager</h2><figure class="kg-card kg-image-card"><img src="https://vinta-cms.s3.amazonaws.com/media/filer_public/57/5c/575cd37a-8435-43f2-956d-645c9e89c9ee/iqkeyboardmanager.gif" class="kg-image" alt="IQKeyboardManager"></figure><p><br>So far, the best solution I’ve found (both in terms of simplicity and user experience) is <a href="https://github.com/hackiftekhar/IQKeyboardManager">IQKeyboardManager</a>. This lib does <em><strong>not require any extra configuration</strong></em>, you add it to your project and it’s already working. So add it to your <code>Podfile</code>:</p><pre><code>pod ‘IQKeyboardManager’ </code></pre><p>run:</p><pre><code>pod install </code></pre><p>and that’s all, your input fields will not be covered by the keyboard anymore.</p>