Fixed long UITextView's to scroll to the the cursor position instead of the bottom of the UITextView #323
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In a UITextView with a really long amount of text (think paragraphs) the behaviour of scrolling to the bottom of the text view when the keyboard is shown makes it very difficult to edit text that's at the top or middle of the text view, as the cursor is then off screen. This is especially a problem since when scrolling up to find the cursor the keyboard is dismissed. Please see here for a demonstration of the issue: http://youtu.be/dJRo4eZALOQ (or simply use the Basic Example project and paste a few paragraphs of Lorem Ipsum text into the About section of the registration form).
• Updated the code to do keyboard calculations and scrolling animations on UIKeyboardDidShowNotification instead of UIKeyboardWillShowNotification as the values returned for getting the cursor location weren't correct for where the user had selected in UIKeyboardWillShowNotification.
• Calculating position of cursor to see if the tableview needs scrolling (if it's not covered by the keyboard then there's no need to scroll).
• Makes sure the cursor is at least 3 lines above the keyboard so that there's still some context of the words surrounding the cursor.
• No longer using animation values from the NSNotification since scroll animation is occurring after the keyboard is shown and therefor isn't keeping in synch