Created
April 14, 2016 08:14
-
-
Save phucnm/77a4ba13f30efff0c475b2c7e56c2d1a to your computer and use it in GitHub Desktop.
Detect current page number in paging enabled Collection view
This file contains 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
// 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