I have a UIScrollView with 10 pages. I am able to flick between them. I also want to have 2 buttons (a back button and a next button) which when touched will go to the previous or next page. I can't seem to figure out a way to do this though. A lot of my code comes from Apple's page control sample code. Can anybody help?
Thanks
You just tell the buttons to scroll to the page's location:
Here is an implementation for Swift 4:
and is easily invoked by calling:
Edit:
A nicer way of doing this is to support both horizontal and vertical pagination. Here is a convenient extension for that:
This creates an extension on UIScrollView where you can scroll to any page, vertical or horisontal.
Here is a static method in swift:
If scrollRectToVisible doesn't work try this :
scrollRectToVisible was not working for me, so I had to animate the contentOffset. This code works in swift 3.
Swift Solution