There are various ways to move a view to accommodate the keyboard when it opens.

In this 2 minute video tutorial, I demonstrate one method that I really like, which is to let Auto Layout and Constraints do the work.



The code is available on GitHub.

UPDATE 22 July 2018. This video is from 2015, and although it is still close, the code has changed slightly for this technique. Please see the project in GitHub for the latest tweaks as of Swift 4.

This looks best in Full Screen 1080p.

Note: In the video, I had a view.setNeedsLayout() after changing the constraint constant. This is not needed, since the constraint change effectively sets the view as needing a layout already. I’ve removed it in the GitHub version.

You can also see a written description of this technique for moving the keyboard and using constraints in code here in a more recent tutorial.

I’ve recently updated the code in GitHub to be Swift 3 compliant. Also remember that if your keyboard doesn’t open in a simulator, make sure you have toggled the software keyboard ON in the simulator.