现在,有这样的一个需求,我们其中有一个页面,页面里面是tableview,当我们从其他页面进入这个页面的时候,我们需要让这个tableview里面的cell,依次的从屏幕的最左端移动到屏幕的最右端,就是原来的位置。其实,熟悉tableview的API,这个实现不是很难,就是几句代码就能够完成;
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
CGRect cellFrameStart = cell.contentView.frame;
cellFrameStart.origin.x = cellFrameStart.size.width;
cell.contentView.frame = cellFrameStart;
NSTimeInterval time = indexPath.row*0.05;
[UIView animateWithDuration:0.6 delay:time options:UIViewAnimationOptionCurveEaseInOut animations:^{
CGRect cellFrameEnd = cell.contentView.frame;
cellFrameEnd.origin.x = 0;
cell.contentView.frame = cellFrameEnd;
} completion:^(BOOL finisahed){
}];
}
效果图如下:
动画图