【问题标题】:iOS - Swipe to delete while also allowing moving rowsiOS - 滑动删除,同时还允许移动行
【发布时间】:2015-05-26 18:02:01
【问题描述】:

我的表格视图处于编辑模式,允许移动我的单元格。是否也可以添加滑动删除,而不是使用红色圆圈删除按钮。

我希望能够只显示移动单元格图像,允许移动,并且还可以滑动删除。

这可能吗?

这就是我目前正在做的事情。

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1) {
        return UITableViewCellEditingStyleDelete;
    }
    else
        return UITableViewCellEditingStyleNone;
}

-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1)
        return YES;
    else
        return NO;
}

- (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
    return NO;
}

【问题讨论】:

    标签: ios objective-c uitableview


    【解决方案1】:

    这绝对是可能的,虽然不像你想的那么简单。这分为三个部分:

    1. “滑动”手势
    2. UI 动画
    3. 删除操作

    “滑动”手势可能不应该是UISwipeGestureRecognizer。 UIPanGestureRecognizer 将随着用户的手指移动而更新,并与用户期望的相符。

    动画应该有两个部分:更新和完成。更新应该简单地平移单元格内的单元格视图以跟随用户的手指。一旦手势达到“完成”点,然后动画单元格视图离开屏幕。

    最后,如果您使用过UITableViewDelegate 方法,那么删除操作应该很熟悉。如果没有,here's a link to a helpful answer on the subject。

    我实际上会乱序执行这些。首先,以编程方式测试删除一行。当它起作用时,添加一个UIPanGestureRecognizer 来调用删除行。然后使用平移手势移动单元格视图。最后,动画完成单元格视图的移动。

    【讨论】:

      猜你喜欢
      • 2012-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多