banner



How To Update Pageviewcontroller From Other View Controller Swift

Pageboy

TL;DR UIPageViewController washed properly.

⭐️ Features

  • Simplified data source management & enhanced delegation.
  • Dynamically insert & remove pages.
  • Infinite scrolling support.
  • Automatic timer-based folio transitioning.
  • Support for custom blithe page transitions.

📋 Requirements

Pageboy requires iOS 9 / tvOS ten; and is compatible with Swift five.

📲 Installation

Swift Parcel Director

Pageboy is compatible with Swift Parcel Manager and can be integrated via Xcode.

CocoaPods

Pageboy is as well available through CocoaPods:

Carthage

Pageboy is as well available through Carthage:

iii.6 ">

              github "uias/Pageboy" ~> 3.6                          

🚀 Usage

  • The Nuts
  • PageboyViewControllerDelegate
  • Navigation
  • Insertion & Deletion

The Basics

  1. Create an example of a PageboyViewController and provide it with a PageboyViewControllerDataSource.
              class              PageViewController:              PageboyViewController,              PageboyViewControllerDataSource              {              override              func              viewDidLoad() {              super.viewDidLoad()              self.dataSource              =              cocky              } }
  1. Implement the PageboyViewControllerDataSource functions.
              func              numberOfViewControllers(in              pageboyViewController: PageboyViewController)              ->              Int              {              return              viewControllers.count              }              func              viewController(for              pageboyViewController: PageboyViewController,              at              index: PageboyViewController.PageIndex)              ->              UIViewController?              {              return              viewControllers[index] }              func              defaultPage(for              pageboyViewController: PageboyViewController)              ->              PageboyViewController.Page?              {              render              nil              }

PageboyViewControllerDelegate

The consul functions provided past a PageboyViewController are much more reliable and useful than what a raw UIPageViewController provides. You tin can use them to detect 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.

              func              pageboyViewController(_              pageboyViewController: PageboyViewController,              willScrollToPageAt              index:              Int,                              management              : NavigationDirection,                              blithe              :              Bool)

didScrollToPosition

Scrolled to a relative position along the way transitioning to a new page.

              func              pageboyViewController(_              pageboyViewController: PageboyViewController,              didScrollTo              position: CGPoint,                              direction              : NavigationDirection,                              animated              :              Bool)

didScrollToPage

Successfully completed a scroll transition to a folio.

              func              pageboyViewController(_              pageboyViewController: PageboyViewController,              didScrollToPageAt              index:              Int,                              management              : NavigationDirection,                              animated              :              Bool)

didReload

Kid view controllers have been reloaded.

              func              pageboyViewController(_              pageboyViewController: PageboyViewController,              didReloadWith              currentViewController: UIViewController,                              currentPageIndex              : PageIndex)

Navigation

Y'all tin navigate programmatically through a PageboyViewController using scrollToPage():

pageViewController.scrollToPage(.side by side,              blithe:              true)
  • Infinite scrolling can be enabled with .isInfiniteScrollEnabled.
  • Interactive scrolling tin as well be controlled with .isScrollEnabled.

Insertion & Deletion

Pageboy provides the ability to insert and delete pages dynamically in the PageboyViewController.

              func              insertPage(at              alphabetize: PageIndex,              then              updateBehavior: PageUpdateBehavior)              func              deletePage(at              alphabetize: PageIndex,              then              updateBehavior: PageUpdateBehavior)

This behaves similarly to the insertion of rows in UITableView, in the fact that you have to update the information source prior to calling any of the update functions.

Instance:

              permit              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 exist configured by passing a PageUpdateBehavior value other than .scrollToUpdate.

⚡️ Other Extras

  • reloadData() - Reload the view controllers in the folio view controller. (Reloads the information 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.

Blithe Transitions

Pageboy as well provides custom transition support for blithe transitions. This tin can be customized via the .transition property on PageboyViewController.

pageboyViewController.transition              =              Transition(style: .push,              duration:              ane.0)

Annotation: By default this is set to goose egg, which uses the standard blitheness provided by UIPageViewController.

Motorcar Scrolling

PageboyAutoScroller is available to set up up timer based automatic scrolling of the PageboyViewController:

pageboyViewController.autoScroller.enable()

Support for custom break duration and other scroll behaviors is also bachelor.

👨🏻‍💻 About

  • Created by Merrick Sapsford (@MerrickSapsford)
  • Contributed to past a growing list of others.

❤️ 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.

GitHub

https://github.com/uias/Pageboy

Source: https://swiftobc.com/repo/uias-Pageboy-swift-pagination

Posted by: robinsonhans1996.blogspot.com

0 Response to "How To Update Pageviewcontroller From Other View Controller Swift"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel