michaeltyson / TPKeyboardAvoiding

A drop-in universal solution for moving text fields out of the way of the keyboard in iOS
http://atastypixel.com/blog/a-drop-in-universal-solution-for-moving-text-fields-out-of-the-way-of-the-keyboard/
zlib License
5.81k stars 925 forks source link

Issue in the algorithm implementation to find next responder #124

Open fodlife opened 10 years ago

fodlife commented 10 years ago

I have found the bug in implementation of the algorithm to find next responder.

Function : TPKeyboardAvoiding_findTextFieldAfterTextField Part : the condition expression if the found textfield (or textview) is the exact "Next" field of the priortextfield.

childView != priorTextField && CGRectGetMinY(frame) >= priorFieldOffset && CGRectGetMinY(frame) < *minY && !(frame.origin.y == priorTextField.frame.origin.y && frame.origin.x < priorTextField.frame.origin.x)

This should be done like this (the frames should be relative values based on the superview)

childView != priorTextField && CGRectGetMinY(frame) >= priorFieldOffset && CGRectGetMinY(frame) < *minY && !(CGRectGetMinY(frame) == priorFieldOffset && CGRectGetMinX(frame) < priorFieldOffsetX)

Here, priorFieldOffsetX = CGRectGetMinX([self convertRect:priorTextField.frame fromView:priorTextField.superview])

Because of this issue, TPKeyboardAvoidingTableView is sometimes not finding the correct next textfield inside the dynamically added tableviewcell if the cell has 2 textfields that have the same y value.

AnthonyMDev commented 9 years ago

I believe I've fixed this with #175. Would you mind trying out my fork with that pull request implemented and let me know if this solves your problem?