Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
- let cellWidth = CGFloat(155)
- let cellSpacing = CGFloat(6)
- let leftOffset = scrollView.contentOffset.x - scrollView.contentInset.left
- let cellWidth = cellWidth + cellSpacing
- let rawMovement = leftOffset / cellWidth
- // round down, but if scrolling right, round up
- var proposedPage = Int(rawMovement)
- if velocity.x == 0 {
- proposedPage = Int(round(rawMovement))
- } else if velocity.x > 0 {
- proposedPage += 1
- }
- let newOffset = cellWidth * CGFloat(proposedPage)
- targetContentOffset.pointee = CGPoint(x: newOffset, y: targetContentOffset.pointee.y)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement