Created
July 25, 2018 02:32
-
-
Save brownsoo/e669ec950067d69a783fbbf9e643e5cc to your computer and use it in GitHub Desktop.
UITableView snap tp cells
This file contains hidden or 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 scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) { | |
if scrollView == suggestionsTableView { | |
let cellHeight = CGFloat(60.0) | |
let y = targetContentOffset.pointee.y + scrollView.contentInset.top + (cellHeight / 2) | |
let cellIndex = floor(y / cellHeight) | |
targetContentOffset.pointee.y = cellIndex * cellHeight - scrollView.contentInset.top | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment