NEWEST SOLUTION(2017年12月12日)
添加夫特4.0版本的动画的方法的。它应然后以同样的方式,如下所述溶液来实现:
func animate() {
for cell in self.tableView.visibleCells {
cell.frame = CGRect(x: self.tableView.frame.size.width, y: cell.frame.origin.y, width: cell.frame.size.width, height: cell.frame.size.height)
UIView.animate(withDuration: 1.0) {
cell.frame = CGRect(x: 0, y: cell.frame.origin.y, width: cell.frame.size.width, height: cell.frame.size.height)
}
}
}
NEWER SOLUTION(2015年9月5日)
添加夫特2.0版本的动画的方法的。它应该再以同样的方式被实现为下面的解决方案:
func animate() {
for cell in self.tableView.visibleCells {
cell.frame = CGRectMake(320, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height)
UIView.animateWithDuration(1.0) {
cell.frame = CGRectMake(0, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height)
}
}
}
新的解决方案(2014年9月28日)
我修改了解决一下,以便实施更容易,并使其与iOS8一起工作。所有你需要做的是在你的TableViewController添加此animate
方法,并调用它,只要你想它动画(例如,在你重装的方法,但你可以在任何时候调用它):同样
- (void)animate
{
[[self.tableView visibleCells] enumerateObjectsUsingBlock:^(UITableViewCell *cell, NSUInteger idx, BOOL *stop) {
[cell setFrame:CGRectMake(320, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height)];
[UIView animateWithDuration:1 animations:^{
[cell setFrame:CGRectMake(0, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height)];
}];
}];
}
,改变你喜欢的动画。这个特定的代码会以较慢的速度从右侧开始对单元格进行动画处理。
老办法(2013年6月6日)
您可以通过实现自己的UITableView并重写insertRowsAtIndexPaths方法做到这一点。下面是如何可能看起来像在那里,细胞会从右侧推的例子,真的慢慢地(1级秒钟的动画):
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
{
for (NSIndexPath *indexPath in indexPaths)
{
UITableViewCell *cell = [self cellForRowAtIndexPath:indexPath];
[cell setFrame:CGRectMake(320, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height)];
[UIView beginAnimations:NULL context:nil];
[UIView setAnimationDuration:1];
[cell setFrame:CGRectMake(0, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height)];
[UIView commitAnimations];
}
}
你可以玩的动画自己。这个方法不会被表视图自动调用,所以你必须重写表视图委托中的reloadData方法并自己调用这个方法。
COMMENT
的reloadData方法应该是这个样子:
- (void)reloadData
{
[super reloadData];
NSMutableArray *indexPaths = [[NSMutableArray alloc] init];
for (int i = 0; i < [_data count]; i++)
[indexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];
[self insertRowsAtIndexPaths:indexPaths withRowAnimation:0];
}
致谢!奇迹般有效。 – 2013-03-08 23:32:28
它只是重写'insertRowsAtIndexPaths:withRowAnimation:'方法?当我重写它,然后用'beginUpdates:'和'endUpdates:'方法调用时,应用程序崩溃在'[UITableView _endCellAnimationsWithContext:]' – 2013-06-05 20:46:04
请参阅我的编辑.. – 2013-06-08 11:18:10