Scroll View School · Challenge: Adding Keyboard Insets | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/9223-scroll-view-school/lessons/18

Thanks for the tutorial, but I have a quick question. Is this an iOS 12 feature to automatically scroll when text field is covered by keyboard frame? E.g. when I set focus to Email field after focus was on Name field.

I don’t believe that is a new iOS 12 feature, but if you find any information to the contrary, please do let us know! :]

Hello Katie and Jesse.
I want to share you that I did the keyboard inset challenge. So I found that your final solution maybe need a little improve. I’ve changed the last three lines of adjustInsetForKeyboard method to:

let adjustmentHeight = keyBoardFrame.height * ( show ? 1 : 0)
scrollView.contentInset.bottom = adjustmentHeight
scrollView.scrollIndicatorInsets.bottom = adjustmentHeight

In this way when you hide the keyboard the scroll return to its origin bottom contentInset.

This has been my first comment here. I’m very glad with your videos.

3 Likes

@alfonso990 Thank you for sharing your solution - much appreciated! :]

Thanks for the solution - with the original code the first time you clicked the return button on the keyboard the scrollview would increase the inset even further (but then work properly).
Still, even though alfonso’s code does work better, it still shows some weird behaviour: The inset increases further when clicking on the bottom text field than it does when clicking on the top one.

Thank you for sharing this solution. cheers!