Skip to content

Instantly share code, notes, and snippets.

@phucnm
Created April 14, 2016 08:14
Show Gist options
  • Save phucnm/77a4ba13f30efff0c475b2c7e56c2d1a to your computer and use it in GitHub Desktop.
Save phucnm/77a4ba13f30efff0c475b2c7e56c2d1a to your computer and use it in GitHub Desktop.
Detect current page number in paging enabled Collection view
// Scrollview.tag will equal to your collection view's tag
// Use page to update page control or whatever
func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
print("tag = \(scrollView.tag)")
let pageWidth = scrollView.frame.size.width
let page = Int(floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1)
print("page = \(page)")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment