如果我逐行插入,则此动画从下到上动画工作。并在当时从上到下滚动时设置一个条件,而不是动画,但我也想在从下到上播放一次动画后停止动画。
willDisplayCell
tableview
方法:
if (tempIndex == nil)
{
CGRect myRect = [tableView rectForRowAtIndexPath:indexPath];
//instead of 568, choose the origin of your animation
cell.frame = CGRectMake(cell.frame.origin.x,
cell.frame.origin.y + 568,
cell.frame.size.width,
cell.frame.size.height);
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
//instead of -30, choose how much you want the cell to get "under" the cell above
cell.frame = CGRectMake(myRect.origin.x,
myRect.origin.y ,
myRect.size.width,
myRect.size.height);
} completion:^(BOOL finished){
[UIView animateWithDuration:0.3 animations:^{
cell.frame = myRect;
}];
}];
tempIndex = indexPath;
}
else if (tempIndex.row < indexPath.row)
{
CGRect myRect = [tableView rectForRowAtIndexPath:indexPath];
//instead of 568, choose the origin of your animation
cell.frame = CGRectMake(cell.frame.origin.x,
cell.frame.origin.y + 568,
cell.frame.size.width,
cell.frame.size.height);
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
//instead of -30, choose how much you want the cell to get "under" the cell above
cell.frame = CGRectMake(myRect.origin.x,
myRect.origin.y,
myRect.size.width,
myRect.size.height);
} completion:^(BOOL finished){
[UIView animateWithDuration:0.3 animations:^{
cell.frame = myRect;
}];
}];
tempIndex = indexPath;
}
else
{
tempIndex = indexPath;
}
您可以维护一个整数,该整数是表视图动画之前的行的索引
//assuming animatedTill as a property initialized to 0
if (indexpath.row > self.animatedTill)
{
CGRect myRect = [tableView rectForRowAtIndexPath:indexPath];
//instead of 568, choose the origin of your animation
cell.frame = CGRectMake(cell.frame.origin.x,
cell.frame.origin.y + 568,
cell.frame.size.width,
cell.frame.size.height);
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
//instead of -30, choose how much you want the cell to get "under" the cell above
cell.frame = CGRectMake(myRect.origin.x,
myRect.origin.y ,
myRect.size.width,
myRect.size.height);
} completion:^(BOOL finished){
[UIView animateWithDuration:0.3 animations:^{
cell.frame = myRect;
self.animatedTill = indexpath.row
}];
}];
}