Skip to content

Instantly share code, notes, and snippets.

@aataraxiaa
Created March 5, 2017 11:23
Show Gist options
  • Save aataraxiaa/bd49a4b3c626a5b3d510db68a1d9dada to your computer and use it in GitHub Desktop.
Save aataraxiaa/bd49a4b3c626a5b3d510db68a1d9dada to your computer and use it in GitHub Desktop.
Method of calculating the centre cell in ScalingCarousel
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
var centerCell: UICollectionViewCell? = nil
// Get cell being displayed in the center of the screen
// Do this by getting the cell that is fully visible
for cell in scalingCarousel.visibleCells {
let cellRect = scalingCarousel.convert(cell.frame, to: nil)
// Get the cell that is fully visible, this will have an origin x value between 30 and 70
if cellRect.origin.x > 30 && cellRect.origin.x < 70 {
centerCell = cell
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment