2013-07-19 29 views
1

如何在開始時向每行添加動畫UITableView?我想從左到右或從右到左的每一行都有一個動畫效果。動畫到uitableview中的每一行

相關的代碼,並沒有得到預期的效果:

float originalY = cell.frame.origin.y; 
float originalH = cell.bounds.size.height; 

[UITableViewCell animateWithDuration:1.0f delay:0.0f options:UIViewRowAnimationLeft animations:^{ 
    cell.frame = CGRectMake(cell.frame.origin.x, (originalY + originalH), cell.bounds.size.width, 0); 

}completion:^(BOOL finished) { 
    NSLog(@"Animation is complete"); 
}]; 

回答

0

使用此方法:

+ (id)indexPathWithIndexes:(const NSUInteger [])indexes length:(NSUInteger)length; 

例:

NSIndexPath *indexPath = [NSIndexPath indexPathWithIndexes:HERE_PASS_INDEXES length:HERE_PASS_LENGTH]; 
[your_table reloadRowsAtIndexPaths:indexPath withRowAnimation:UITableViewRowAnimationLeft]; 

或用途:

- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation; 

// Make the index paths // 

NSIndexPath* indexPath1 = [NSIndexPath indexPathForRow:1 inSection:1]; 
NSIndexPath* indexPath2 = [NSIndexPath indexPathForRow:2 inSection:1]; 
NSIndexPath* indexPath3 = [NSIndexPath indexPathForRow:3 inSection:2]; 
NSIndexPath* indexPath4 = [NSIndexPath indexPathForRow:5 inSection:2]; 
// Add them in an index path array 
NSArray* indexArray = [NSArray arrayWithObjects:indexPath1, indexPath2,indexPath3,indexPath4, nil]; 


[your_tablename reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade]; 
0

哪裏放置代碼?如果它位於cellForRowAtIndexPath中,則表示它太快,因爲該表尚未繪製。

嘗試重新加載tavleview,將單元格設置爲cellForRow中的初始框架(如果您希望它從左側進入,請將tableView.width作爲x點)。 重新加載完成後,創建一個遍歷單元格並調用您所寫的動畫塊的函數。