Adjust Scroll View Content Inset Based on Keyboard Frame

Reveal text fields in form when keyboard is shown/hidden

In cases where we have form containing UITextFields embedded in UIScrollView, when keyboard is shown and hidden, we want UIScrollView to be adjusted accordlingly.

We start in the viewWillAppear method by adding the following code:

Then we define the method to handle keyboard notifications:

This single method handles both cases, with keyboard shown or hidden states.

Notice the top: 64.0 is because of status bar height 20.0 and navigation bar height 44.0. If you do not have UIViewController in embedded in UINavigationController or the navigation bar is hidden, you can set the top value to 20.0

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s