Skip to content

Instantly share code, notes, and snippets.

@ltebean
Created August 29, 2014 09:06
Show Gist options
  • Save ltebean/eb609f09bef0ef30e9a3 to your computer and use it in GitHub Desktop.
Save ltebean/eb609f09bef0ef30e9a3 to your computer and use it in GitHub Desktop.
tableview visible cells animation
self.tableView.alpha = 0.0f;
[self.tableView reloadData];
// Store a delta timing variable so I can tweak the timing delay
// between each row’s animation and some additional
CGFloat diff = .05;
CGFloat tableHeight = self.tableView.bounds.size.height;
NSArray *cells = [self.tableView visibleCells];
// Iterate across the rows and translate them down off the screen
for (NSUInteger i = 0; i < [cells count]; i++) {
UITableViewCell *cell = [cells objectAtIndex:i];
cell.transform = CGAffineTransformMakeTranslation(0, tableHeight);
}
// Now that all rows are off the screen, make the tableview opaque again
self.tableView.alpha = 1.0f;
// Animate each row back into place
for (NSUInteger i = 0; i < [cells count]; i++) {
UITableViewCell *cell = [cells objectAtIndex:i];
[UIView animateWithDuration:1.2 delay:diff*i usingSpringWithDamping:0.77
initialSpringVelocity:0 options:0 animations:^{
cell.transform = CGAffineTransformMakeTranslation(0, 0);
} completion:NULL];
}
@yam-liu
Copy link

yam-liu commented Apr 26, 2017

Don't forget [self.tableView reloadData]; 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment