动画到uitableview中的每一行

时间:2013-07-19 05:18:16

标签: ios uiview 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");
}];

3 个答案:

答案 0 :(得分: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];

答案 1 :(得分:0)

Animated-TableViewCell结帐源代码。

答案 2 :(得分:0)

该代码放在哪里?如果它在cellForRowAtIndexPath中,那意味着它太快了,因为还没有绘制表。

尝试重新加载tavleview,将单元格设置为cellForRow中的初始帧。(如果您希望它从左侧进入,请将tableView.width作为x点。) 重新加载完成后,创建一个遍历单元格并调用您编写的动画块的函数。