Created
August 22, 2018 13:50
-
-
Save aguilarpgc/60bac869313e85560c694fec0af7ea11 to your computer and use it in GitHub Desktop.
Simple fade animation at horizontal scrolling in UIScrollView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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