Elegant keyboard animation in swift

Warren HansenSwifty ThoughtsLeave a Comment


I attend the Learn Swift LA meet up to sharpen my swift skills and hang out with other developers. The topics rotate weekly from beginner to advanced so the group can continue to provide help and ideas to those new to swift and well as having more advanced weeks for seasoned developers. Emil Safier hosted our meeUp. He had a great presentation on many things including moving the view when the keyboard appears. I’ve always done this by moving the view up but Emil had a new approach that I really liked.

First, he built a UI and here we see the problem, when you access the keyboard it will cause the text entry fields to be blocked.

Problem keyboard blocks some fields in your UI

Solution use the constraint to animate the keyboard up with a curve animation and fade the image of the photograph. I think this is very clever and looks G R E A T. Next Emil made an @IBOutlet for the constraint and when the keyboard notifies that it’s appearing that constraint is made larger. At the same time, he reduced the transparency of the user image.

Here is the function Emil created

I wrote a simple UI with just the keyboard animation.

What I really like about this is the image fade and how the view moves separately from the keyboard. All of these options can be tweaked from one function and I dig the simplicity of that.

Here is my git repo of animate keyboard

Also here is Emil’s Wiki and GitRepo of all the features he discussed in out Meetup. It’s called Project Bob and was the first of 3 lessons designed to take you through many things a swift developer does like; gather user information, add items to a table view, persist the information with core data.

Wednesday Nights – Come join us at the next Learn Swift LA meet up and you’ll learn a few new things and make a few new friends… it’s a great way to spend the evening.

Saturday Mornings – Drop into our Saturday Morning Peer Lab where we work together on our projects. If you have a question you can ask the group and you can also help others who are newer than you. We have a team environment where anyone can learn or lend a hand.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.