Navigate to specific page in scrollView with paging, programmatically

Swift 5 you can easily use scrollView.scrollRectToVisible

If the Horizontal paging scroll view implemented, which has the size of default view width of the device and wanted to navigate to number n page:

scrollView.scrollRectToVisible(CGRect(x: self.view.center.x * n, y: self.view.center.y, width: self.view.frame.width, height: self.view.frame.height) ,animated: true)

You just have to define the CGRect() position according to your scrollview configurations.


You have to calculate the corresponding scroll position manually. To scroll to page i:

[scrollView setContentOffset:CGPointMake(scrollView.frame.size.width*i, 0.0f) animated:YES];