Created
August 9, 2015 22:37
-
-
Save dbonates/7ba0dcd1f6e44f9033a6 to your computer and use it in GitHub Desktop.
Tableview scroll dumping cells animation
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
| 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