Skip to content

Instantly share code, notes, and snippets.

@guarani
Created April 8, 2015 02:05
Show Gist options
  • Save guarani/65ade8d7fde7184d6f05 to your computer and use it in GitHub Desktop.
Save guarani/65ade8d7fde7184d6f05 to your computer and use it in GitHub Desktop.
A UITableView scrolls to whole UITableViewCells
func scrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
println("scrollViewWillEndDragging")
println("targetContentOffset: \(targetContentOffset.memory.y)")
var targetContentOffsetCorrected: CGPoint = targetContentOffset.memory
targetContentOffsetCorrected.y += contentInsetY
println("targetContentOffsetCorrected: \(targetContentOffsetCorrected.y)")
let targetCellIndexPath = self.tableView.indexPathForRowAtPoint(targetContentOffsetCorrected)
println("targetCellIndexPath row: \(targetCellIndexPath?.row)")
let targetCellRect = self.tableView.rectForRowAtIndexPath(targetCellIndexPath!)
println("targetCellRect: \(targetCellRect)")
var targetCellYCenter = targetCellRect.origin.y
println("targetCellYCenter: \(targetCellYCenter)")
// let isJumpingDown = (targetContentOffsetCorrected.y % cellHeight) > (cellHeight / 2)
//
// if isJumpingDown == false {
// targetCellYCenter += cellHeight
// }
targetContentOffset.memory.y = targetCellYCenter - contentInsetY
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment