michaeltyson/TPKeyboardAvoiding — Issue #7: scroll offset does not adjust when focus changes between text fields
Author: sclamage
Created: 2012-01-24 18:00:30+00:00
State: open

This is oh-so-close to being the mythical drop-in fix I was looking for, except for this...

I have a view consisting of a plain old TPKeyboardAvoidingScrollView with multiple UITextFields (i.e. no table). Everything works fine if I tap in a field and back out - if the field would be obscured by the keyboard, it scrolls up, and when it resigns first responder status it scrolls back into place when the keyboard hides.

However, if one field is partially obscured by the keyboard and I tap in it, the view does not scroll up to make it visible. I believe this is because the keyboard doesn't get hidden/reshown in that case, so there's nothing to tell your scrollview that it needs to make an adjustment.

I have a similar issue in handling of -textFieldShouldReturn:. My app implements that so that the keyboard's "next" button will allow the user to move between fields. The implementation just sets the next field as the new first responder. But since this doesn't trigger a keyboard hide/show, the scrollview doesn't know that it needs to make an adjustment.

Unfortunately, there is no notification sent when the first responder changes, so I don't think you can fix this without adding some collaboration between the app and your scrollview class. It probably will need to be a UITextFieldDelegate to handle this correctly. Maybe you can think of a better solution.