Skip to content

Instantly share code, notes, and snippets.

@dbonates
Created August 9, 2015 22:37
Show Gist options
  • Select an option

  • Save dbonates/7ba0dcd1f6e44f9033a6 to your computer and use it in GitHub Desktop.

Select an option

Save dbonates/7ba0dcd1f6e44f9033a6 to your computer and use it in GitHub Desktop.
Tableview scroll dumping cells animation
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
// instead of return perhaps should do a simpler animation
if !tableView.dragging || indexPath.row == movies.count { return }
let mvCell = cell as! MovieTableViewCell
if toTop {
mvCell.contentView.transform = CGAffineTransformMakeTranslation(0, -80)
} else {
mvCell.contentView.transform = CGAffineTransformMakeTranslation(0, 80)
}
UIView.animateWithDuration(1, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: UIViewAnimationOptions.CurveEaseOut, animations: { () -> Void in
cell.contentView.transform = CGAffineTransformMakeTranslation(0, 0)
}, completion: nil)
}
override func scrollViewWillBeginDragging(scrollView: UIScrollView) {
currentOffset = scrollView.contentOffset.y
}
override func scrollViewDidScroll(scrollView: UIScrollView) {
let newOffset = scrollView.contentOffset.y
if newOffset > currentOffset {
toTop = false
} else {
toTop = true
}
currentOffset = newOffset
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment