使TableviewCell排序手势占满cell条

来源:互联网 发布:淘宝海外买手 编辑:程序博客网 时间:2024/05/02 04:19

参考:http://blog.sina.com.cn/s/blog_702e40a80101iue2.html

另一种思路:http://www.jianshu.com/p/ce382f9bc794


突发奇想让tableviewcell排序的指示图标改动,能长按cell的任意位置可执行移动排序,主要思路就是让指示图标层形变。同样用形变的方法也可以让系统的移动指示图标位移。

先按照常规的做法 写好以下代码

//默认编辑模式下,每个cell左边有个红色的删除按钮,设置为None即可去掉- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{    return UITableViewCellEditingStyleNone;}//是否允许indexPath的cell移动- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{    return YES;}- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{       NSUInteger fromSection = [sourceIndexPath section];  //要移动的那个cell integer    NSUInteger toSection = [<span style="font-family: Arial, Helvetica, sans-serif;">destinationIndexPath </span>section]; //要移动位置的那个cell integer    //arrayValue 添加数据的那个可变数组    IGCellData *object = [datas objectAtIndex:fromSection]; // 获取数据        [datas removeObjectAtIndex:fromSection];  //在当前位置删除    [datas insertObject:object atIndex:toSection]; //插入的位置 //更新数据源[tableView reloadData];}




- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{       UAAMDirectoryCell *cellValue=(UAAMDirectoryCell *)cell;    for(UIView* view in cellValue.subviews)    {        if([[[view class] description] isEqualToString:@"UITableViewCellReorderControl"])        {            cellValue.movedReorderControl.frame=CGRectMake(0, 0, CGRectGetMaxX(view.frame)*2,CGRectGetMaxY(view.frame));//设置图标隐藏,形变放大            for (UIView *subview in view.subviews) {                if ([subview isKindOfClass:[UIImageView class]]) {                    subview.hidden =YES;                }            }            cellValue.movedReorderControl.userInteractionEnabled=YES;            [cellValue.movedReorderControl addSubview:view];            CGAffineTransform transform = CGAffineTransformIdentity;            cellValue.movedReorderControl .transform=CGAffineTransformScale(transform, SCREEN_SIZE.width/view.width*1.00, 1);        }    }}

movedReorderControl 是我在cell里面声明的一个View,在cell里判断编辑状态添加这个view,否则移除。

以上为核心的部分,像形变图层会覆盖cell表面,tableView进入编辑状态才可以进行移动 等细节方面还要多注意

0 0
原创粉丝点击