Skip to content

Detect page scrolling

Evgenii Neumerzhitckii edited this page Jun 17, 2016 · 8 revisions

Sometimes it is needed to run some code when user changes pages in the scroll view. For example, one may want to update a label with the name of the author for the currently displayed picture.

It can be done by implementing a standard scroll view delegate with the scrollViewDidScroll method:

  1. Firstly, subclass your view controller from UIScrollViewDelegate:
class ViewController: UIViewController, UIScrollViewDelegate {
  1. Secondly, assign the view controller to the delegate property of the scroll view. Make sure to assign the delegate before accessing scrollView.auk property.
override func viewDidLoad() {
    super.viewDidLoad()

    scrollView.delegate = self
    scrollView.auk.show(...
  1. Finally, implement scrollViewDidScroll method in your view controller. In this method you can update your UI based on the current page index.
func scrollViewDidScroll(_ scrollView: UIScrollView) {
   label.text = String(scrollView.auk.currentPageIndex)
}

Note that scrollViewDidScroll method is called very frequently as the scroll view is being scrolled.

Clone this wiki locally