Created
March 5, 2017 11:23
-
-
Save aataraxiaa/bd49a4b3c626a5b3d510db68a1d9dada to your computer and use it in GitHub Desktop.
Method of calculating the centre cell in ScalingCarousel
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
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