Whenever a UITextView has a large textContainerInset
it starts scrolling upwards rapidly when selecting text. For my use case, I have a custom view that I display in the text view to show the comment you are writing a reply to. To accomplish this, I use the textContainerInset
and set the top
portion of that inset to a large value.
Here is a video showing the issue: https://streamable.com/9z57ok
I've also made a very simple sample project to demonstrate and here is the main view controller code: https://gist.github.com/rickharrison/9cf563bcb22130bfafc7d3b5d37c55f2
Is it possible to disable scrolling of the UITextView while the selection UI is shown? Or is there another way I should inset the text to edit?
I found another thread with this issue from years ago, but no solution - https://developer.apple.com/forums/thread/129882
This appears to be a real bug in the way that UITextView calculates the intended scroll position for a given selection point. This bug will be addressed in a future software update (apologies, I am not allowed to provide timelines).
There are some workarounds that you can try, however. One thing I would suggest is to consider some alternatives for textContainerInset
. If you need extra space at the top of your UITextView to place other content, for example, consider instead placing your text view inside of a container UIScrollView. You can set UITextView's isScrollEnabled
to false
, which will then allow you to obtain it's desired content size via intrinsicContentSize
or sizeThatFits:
, which would then allow you to lay out this text view inside of a parent UIScrollView, for which you can place at any arbitrary y
offset.