Adding Resizing

When the screen is rotated, both the scroll view and form view need to be resized. Then the contentSize property needs to be updated.

You already have code to resize the scroll view. Put breakpoints in keyboardDidShow: and keyboardwillHide: and run the app again. Rotate the screen and you see that each method is called. The system hides and shows the keyboard to set it to the correct size. Those methods also correctly set the size of the scroll area.

The form view is also resized when the screen rotates. This happens when the scroll view changes size and updates the layout for its children. All you need to do is update contentSize from the new form view frame. Add the following line of code at the end of both the keyboardDidShow: ...

Get Learning iOS Development: A Hands-on Guide to the Fundamentals of iOS Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.