Skip to content

Instantly share code, notes, and snippets.

@ruan65
Created July 2, 2017 15:39
Show Gist options
  • Save ruan65/3037f077e30532f39aba074a4b384067 to your computer and use it in GitHub Desktop.
Save ruan65/3037f077e30532f39aba074a4b384067 to your computer and use it in GitHub Desktop.
Method for catching CollectionView scroll to top or bottom in Swift
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
if (scrollView.contentOffset.y < -250){
//reach top
print("Topppppppppppppppppppp")
}
if (scrollView.contentOffset.y >= 250 + (scrollView.contentSize.height - scrollView.frame.size.height)) {
//reach bottom
print("Bottommmmmmm........")
}
if (scrollView.contentOffset.y >= 0 && scrollView.contentOffset.y < (scrollView.contentSize.height - scrollView.frame.size.height)){
//not top and not bottom
print("Just scrolled")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment