I have a working carrousel with a few pages and a login form on the last page, with a nice video playing behind. This carrousel is managed by a UIPageViewController, some content is fixed on background video view (which is my entry point, and from there, I instantiate the UIPageVIewController), and other content varies with page swapping. So in every page but the last I need to put a container with two buttons at the bottom of the view, and when the user swipes to the last page, I want this container to move down and disappear in the edge, with the same velocity of user swipe (linked to page swap). Can anybody help guide me to the best way of accomplishing that?
1 Answers
UIPageViewController
inherits from UIViewController
and even though it's most likely using UIScrollView
to do its magic, the scroll view isn't exposed publicly so if you need a way to get accurate reporting on the scrolling position (which is required to accomplish what you want), you're not going to find it in UIPageViewController
.
If you want to do it right, you're going to have to use something other than UIPageViewController
. You can easily accomplish the same functionality using a plain UIScrollView
. Even a UICollectionView
would do if you make its item size equal to your view's frame (or any other collection view trick, of which there are many).
However, if you're also looking for the sexy page curl animations, that's also quite common these days via CATransaction
and setting its type
to pageCurl
(see here).
Once you implement your paging on a UIScrollView
, or any of its subclasses, you can use its contentSize
and contentOffset
properties to tie in your custom animation (move out and disappear).

- 71
- 4
-
Hi @olx, thanks for the feedback. So there's no way to accomplish that using `UIPageViewController`? Can you give a hint on how to do the same with UIScrollView, behaving as page controlling? – Perdona Feb 07 '18 at 18:20
-
The easiest would be to look at the `UIPageViewController` API and replicate it on your custom view controller. In broad strokes, you'd have a `UIScrollView` that would be as tall as your view port and as wide as 3 standard widths of your pages (view controllers). – olx Feb 16 '18 at 08:06
-
Then you'd set your scrollview's `isPagingEnabled ` to true, set its delegate to self and replicate behavior from `UIPageViewControllerDelegate`, i.e. prev/next controller. Then, on `UIScrollViewDelegate`'s scroll did scroll, look at your content offset to figure out what page you're on and invoke prev/next controller methods as appropriate. The idea being that you'd always unload the controller that drops off and append one that's coming in so you always have the previous and next controllers ready. If you're loading something heavy, you may want to expand the pre-loaded pages as needed. – olx Feb 16 '18 at 08:14
-
If your number of pages is going to be relatively small, you can simply make the scroll view as wide as all the widths combined and simply offset each page's view frame by its width. But be careful, if you load a bunch of heavy content all at once, your performance might suffer so may need to do the queue/dequeue trick I eluded to in the previous comment. – olx Feb 16 '18 at 08:17