使TableviewCell排序手势占满cell条

通过形变让UITableViewCell的排序手势可以响应全区域,参考了两篇文章的思路,通过在cell中添加一个View并在编辑状态下显示,使得用户可以长按cell任意位置进行移动排序。形变层覆盖在cell上,确保只有在tableView编辑状态下才能执行移动操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考: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进入编辑状态才可以进行移动 等细节方面还要多注意

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值