I have a content view inside my scroll view that has a small height. The scroll view takes up the entire height of the containing view controller. The bottom most view in the content view is a text view. When the user taps on the text view the keyboard animates up and I animate the bottom anchor of the scroll view up with it. Now the scroll view is short enough to where the content view can scroll. I want to "focus" on the text view so I find its origin relative to the scroll view and use setContentInset(_,animated:)
to scroll the text view onto the screen if it isn't already on screen. I do that with this code:
let point = self.scrollView.convert(self.textView.frame.origin, to: self.scrollView)
self.scrollView.setContentOffset(point, animated: true)
The problem here is that there is extra "dead" space between the bottom of the text view and the top of the keyboard. Yet setContentInset
scrolls to this state nonetheless. When I go to scroll the content view, it snaps down to the top of the keyboard.
here is a visual description. The orange view is the scroll view and the dark gray view represent the top of the keyboard. As you can see, setting the content offset of the scroll view to the origin of the light gray text view means that there is an amount of "dead" (not sure what to call this or how to think about it) space between the end of the scroll view's content and the top of the "keyboard". Because of this, when you go to scroll the scroll view, it immediately snaps the text view to the keyboard.
What can I do to remedy this?