Reputation: 3872
So when a user taps on a cell in my table I don't actually push to a new view controller I just reload the data inside of that tableView.
However, I want to get an effect simular to what it would look like if I did push a new view controller.
Does anybody know how I can slide old content off old content off the screen and new content onto the screen for an entire table?
Upvotes: 7
Views: 3701
Reputation: 4130
Simple animation
func animateTable() {
self.reloadData()
let cells = self.visibleCells
let tableHeight: CGFloat = self.bounds.size.height
for i in cells {
let cell: UITableViewCell = i as UITableViewCell
cell.transform = CGAffineTransform(translationX: 0, y: tableHeight)
}
var index = 0
for a in cells {
let cell: UITableViewCell = a as UITableViewCell
UIView.animate(withDuration: 1.5, delay: 0.05 * Double(index), usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: UIViewAnimationOptions.curveLinear, animations: {
cell.transform = CGAffineTransform.identity
}, completion: nil)
index += 1
}
}
Upvotes: 0
Reputation: 2568
Depending on how many sections you have you can use - (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation
So you could do something like this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0,[self numberOfSectionsInTableView])] withRowAnimation:UITableViewRowAnimationRight];
}
Upvotes: 13