The delegate functions provided by a PageboyViewController are much more reliable and useful than what a raw UIPageViewController provides. You can use them to find out exactly where the current page is, and when it’s moved, where it’s headed.
Infinite scrolling can be enabled with .isInfiniteScrollEnabled.
Interactive scrolling can also be controlled with .isScrollEnabled.
Insertion & Deletion
Pageboy provides the ability to insert and delete pages dynamically in the PageboyViewController.
func insertPage(at index: PageIndex, then updateBehavior: PageUpdateBehavior)
func deletePage(at index: PageIndex, then updateBehavior: PageUpdateBehavior)
This behaves similarly to the insertion of rows in UITableView, in the fact that you have to update the data source prior to calling any of the update functions.
Example:
let index = 2
viewControllers.insert(UIViewController(), at: index)
pageViewController.insertPage(at: index)
The default behavior after inserting or deleting a page is to scroll to the update location, this however can be configured by passing a PageUpdateBehavior value other than .scrollToUpdate.
⚡️ Other Extras
reloadData() - Reload the view controllers in the page view controller. (Reloads the data source).
.navigationOrientation - Whether to orientate the pages horizontally or vertically.
.currentViewController - The currently visible view controller if it exists.
.currentPosition - The exact current relative position of the page view controller.
.currentIndex - The index of the currently visible page.
.parentPageboy - Access the immediate parent PageboyViewController from any child view controller.
Animated Transitions
Pageboy also provides custom transition support for animated transitions. This can be customized via the .transition property on PageboyViewController.
TL;DR UIPageViewController done properly.
⭐️ Features
📋 Requirements
Pageboy requires iOS 11 / tvOS 11; and is compatible with Swift 5.
📲 Installation
Swift Package Manager
Pageboy is compatible with Swift Package Manager and can be integrated via Xcode.
CocoaPods
Pageboy is also available through CocoaPods:
Carthage
Pageboy is also available through Carthage:
🚀 Usage
The Basics
PageboyViewController
and provide it with aPageboyViewControllerDataSource
.PageboyViewControllerDataSource
functions.PageboyViewControllerDelegate
The delegate functions provided by a
PageboyViewController
are much more reliable and useful than what a rawUIPageViewController
provides. You can use them to find out exactly where the current page is, and when it’s moved, where it’s headed.willScrollToPageAtIndex
About to embark on a transition to a new page.
didScrollToPosition
Scrolled to a relative position along the way transitioning to a new page.
didScrollToPage
Successfully completed a scroll transition to a page.
didReload
Child view controllers have been reloaded.
Navigation
You can navigate programmatically through a
PageboyViewController
usingscrollToPage()
:.isInfiniteScrollEnabled
..isScrollEnabled
.Insertion & Deletion
Pageboy provides the ability to insert and delete pages dynamically in the
PageboyViewController
.This behaves similarly to the insertion of rows in
UITableView
, in the fact that you have to update the data source prior to calling any of the update functions.Example:
The default behavior after inserting or deleting a page is to scroll to the update location, this however can be configured by passing a
PageUpdateBehavior
value other than.scrollToUpdate
.⚡️ Other Extras
reloadData()
- Reload the view controllers in the page view controller. (Reloads the data source)..navigationOrientation
- Whether to orientate the pages horizontally or vertically..currentViewController
- The currently visible view controller if it exists..currentPosition
- The exact current relative position of the page view controller..currentIndex
- The index of the currently visible page..parentPageboy
- Access the immediate parentPageboyViewController
from any child view controller.Animated Transitions
Pageboy also provides custom transition support for animated transitions. This can be customized via the
.transition
property onPageboyViewController
.Note: By default this is set to
nil
, which uses the standard animation provided byUIPageViewController
.Auto Scrolling
PageboyAutoScroller
is available to set up timer based automatic scrolling of thePageboyViewController
:Support for custom intermission duration and other scroll behaviors is also available.
👨🏻💻 About
❤️ Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/uias/Pageboy.
👮🏻♂️ License
The library is available as open source under the terms of the MIT License.