0
如果我逐一插入一行,那麼這個動畫是從下到上動畫的。 並且當你在那個時候從上到下滾動而不是動畫的時候做一個條件,但是我也想在一次動畫從下到上的時候停止動畫。UITableview單元格動畫
在tableview
方法
willDisplayCell
:
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;
}
謝謝你......但我有已經解決了這個問題,使用NSMutableArray和comapare [animatedIndexPathArray containsObject:indexPath] – 2014-12-03 12:55:19
在我看來,使用這種整數方法與數組將使用更少的內存和CPU。 – 2014-12-04 05:00:02