Skip to content

Instantly share code, notes, and snippets.

View OnboardingViewController+UIScrollViewDelegate.swift
typealias Interval = (a: CGFloat, b: CGFloat)
extension OnboardingViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let pageIndex = round(scrollView.contentOffset.x / scrollView.frame.width)
pageControl.currentPage = Int(pageIndex)
let maximumHorizontalOffset: CGFloat = scrollView.contentSize.width - scrollView.frame.width
let currentHorizontalOffset: CGFloat = scrollView.contentOffset.x
let percentageHorizontalOffset: CGFloat = currentHorizontalOffset / maximumHorizontalOffset
You can’t perform that action at this time.