I have a few screens worth of content within my UIScrollView which only scrolls vertically.
I want to programmatically scroll to a view contained somewhere in it's hierarchy.
The UIScrollView move so that the child view is at the top of the UIScrollView (either animated or not)
or
Another way is
and i do it with animated like this
Here's an extension I ended up writing.
Usage:
Called from my viewController, self.scrollView is an outlet to the UIScrollView and self.commentsHeader is a view within it, near the bottom:
Code:
You only need the scrollToView method, but leaving in scrollToBottom / scrollToTop methods too as you'll probably need those too, but feel free to delete them.
Here is my answer, this is in swift. This will scroll the pages in scrollview infinitely.
For me, the thing was the navigation bar which overlapped the small portion of the scrollView content. So I've made 2 things:
Where the point's y coordinate is the y coordinate of the frame of the view you want to show relatively to the scrollView's content view.
For scroll to top or bottom with completion of the animation