实现了上下两个cell交换的简单动效,界面如下,点击上,和上面一个cell交换位置,点击下,和下面一个交换位置,点击删除,就删除当前的cell,完整代码,简单说明一下主要cell交换的代码。
UITableViewCell *cell = [_tableView cellForRowAtIndexPath:indexPath];
NSIndexPath *nextIndexPath = [NSIndexPath indexPathForRow:indexPath.row+1 inSection:indexPath.section];
UITableViewCell *nextCell = [_tableView cellForRowAtIndexPath:nextIndexPath];
CGFloat cellY = cell.frame.origin.y;
[UIView animateWithDuration:0.6 animations:^{
//当前这个顶部就和上面一个平齐
CGRect rect = cell.frame;
rect.origin.y = cellY + CGRectGetHeight(nextCell.frame);
cell.frame = rect;
//上面一个需要处理一下,只能基于当前的y+下面的cell的高度,直接交换y轴,位置不准,在刷新表格的时候,会有抖动的现象
CGRect rect1 = nextCell.frame;
rect1.origin.y = cellY;
nextCell.frame = rect1;
}completion:^(BOOL finished)
{[titleArray exchangeObjectAtIndex:index