Skip to content

Instantly share code, notes, and snippets.

@aguilarpgc
Created August 22, 2018 13:50
Show Gist options
  • Select an option

  • Save aguilarpgc/60bac869313e85560c694fec0af7ea11 to your computer and use it in GitHub Desktop.

Select an option

Save aguilarpgc/60bac869313e85560c694fec0af7ea11 to your computer and use it in GitHub Desktop.
Simple fade animation at horizontal scrolling in UIScrollView
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let mod = scrollView.contentOffset.x.truncatingRemainder(dividingBy: scrollView.bounds.size.width)
let difference = abs((2 * mod / (scrollView.bounds.size.width)) - 1)
let factor = (difference * 0.5) + 0.5
self.scrollView.alpha = factor
pageControl.currentPage = Int(scrollView.contentOffset.x / scrollView.frame.size.width);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment