2014-12-02 168 views
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; 
} 

回答

0

可以維持一個整數,是行的指數截止到其中的tableview有動畫

//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 
      }]; 

     }]; 
    } 
+0

謝謝你......但我有已經解決了這個問題,使用NSMutableArray和comapare [animatedIndexPathArray containsObject:indexPath] – 2014-12-03 12:55:19

+0

在我看來,使用這種整數方法與數組將使用更少的內存和CPU。 – 2014-12-04 05:00:02

相關問題