[UITextView scrollRangeToVisible:] is ignoring content inset

Originator:piet.brauer
Number:rdar://25547249 Date Originated:05-Apr-2016 03:10 PM
Status:Behaves correctly Resolved:
Product:iOS SDK Product Version:9.3
Classification:Serious Bug Reproducible:Always
 
Summary:
When I use a full-screen UITextView for text inputs I change the content inset bottom to match the keyboards height. When searching for a string, I want to programmatically search for a match and scroll to the search result. The UITextView scrolls but the search result is below the keyboard.

Steps to Reproduce:
1. Add a view controller with a full screen UITextView
2. Add a bottom contentInset for the keyboard
3. Get a range for a word at the bottom of the text
4. Call `textView.scrollRangeToVisible(range)`
5. You have to manually scroll the last bit to see the result (I highlighted it with a selectedRange)

Expected Results:
I see the result close above the keyboard.

Actual Results:
You have to manually scroll the last bit to see the result

Notes:
You can check out the sample project which searches for a string after 2 seconds and should scroll.

Comments

Apple Developer Relations

Engineering has determined that this issue behaves as intended based on the following information:

The behavior as described is correct. In this case, the view is partially obscured by the keyboard (but it could be any view really). This however does not mean that scrolling a range of text to visible means that the text will actually show up visible (since it is obscured by another view).

If you want this behavior to work as expected, it is better to change the bounds of the textview depending on the keyboard size (as demonstrated in the supplied project) then to change content insets.

In other words: “visible” for the text view does not equal “visible to user of the device”.

By piet.brauer at June 22, 2016, 7:23 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!