Skip to content

Instantly share code, notes, and snippets.

@brownsoo
Created July 25, 2018 02:32
Show Gist options
  • Save brownsoo/e669ec950067d69a783fbbf9e643e5cc to your computer and use it in GitHub Desktop.
Save brownsoo/e669ec950067d69a783fbbf9e643e5cc to your computer and use it in GitHub Desktop.
UITableView snap tp cells
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