Table view cell load animation one after another

后端 未结 7 1019
面向向阳花
面向向阳花 2021-01-31 05:32

I need to animate the load of the table view rows. When the table reloads the data I need the rows get in from the left one after another. How can I achieve this?

7条回答
  •  旧巷少年郎
    2021-01-31 06:16

    tableView:willDisplayCell:forRowAtIndexPath method will be called each time a cell is going to be shown, and since they are getting viewed at the same time it means that they are getting called in different threads and you can't tell iOS SDK to call this method for sequentially. So I think the way to get what you want is to set a delay for each cell when it is being showed.

    -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
        CGFloat delay = indexPath.row * yourSupposedAnimationDuration;
        [UIView animateWithDuration:yourSupposedAnimationDuration delay:delay options:UIViewAnimationOptionCurveEaseIn animations:^{  
            //Your animation code
        }completion:^(BOOL finished) {  
            //Your completion Code
        }];
    }
    

提交回复
热议问题