Animate through multiple pages with UIPageViewController?

I am using UIPageViewController to create a horizontal list of pages. I want to have a button that will cause a transition to a specific page. I can do this by using setViewControllers.

Code Block swift
setViewControllers(
[viewController],
direction: .forward,
animated: true,
completion: nil
)


However this will not animate over multiple pages. The animation makes it appear that the new page is directly next to the old page, even they are not next to each other in my data. An example of the animation I'm thinking of is hitting the home button on the iOS home screen.

One thing I've tried is starting another animation in the completion handler, but for some reason there is no animation on the second transition.

Code Block swift
setViewControllers(
[viewController],
direction: .forward,
animated: true,
completion: { _ in
/*Second Transition*/
self.setViewControllers(
[nextViewController],
direction: .forward,
animated: true,
completion: nil
)
}
)

Answered by andy_ in 619338022
Unless you require some of the animations (like page curl), I would highly recommend using UICollectionView as a basis for a paging view. It can handle more flexible cases and allows you to very easily change pages by doing scrollToItem(at:at:animated:).

Plus, if you need a paging indicator, you can add a UIPageControl separately into the view and be able to position it anywhere, unlike UIPageViewController which only shows the page indicator when you implement some of the dataSource methods and it is only positioned underneath the content and not overlaid.
Accepted Answer
Unless you require some of the animations (like page curl), I would highly recommend using UICollectionView as a basis for a paging view. It can handle more flexible cases and allows you to very easily change pages by doing scrollToItem(at:at:animated:).

Plus, if you need a paging indicator, you can add a UIPageControl separately into the view and be able to position it anywhere, unlike UIPageViewController which only shows the page indicator when you implement some of the dataSource methods and it is only positioned underneath the content and not overlaid.
Animate through multiple pages with UIPageViewController?
 
 
Q