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