tableViewcell上进行手势的添加

未进行操作时是这样的:
这里写图片描述

轻扫或者点击之后为这样的:
这里写图片描述

self.isLeft = NO;//默认为左边按钮是不出现的状态

//编辑按钮
self.editButton = [[UIButton alloc] initWithFrame:CGRectMake(BOUNDS.size.width-46, 0, 46, 43)];
    [_editButton setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [_editButton addTarget:self action:@selector(editAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_editButton];
//删除按钮
  self.deleteBtn = [[UIButton alloc] initWithFrame:CGRectMake(_editButton.frame.origin.x, 47, _editButton.frame.size.width, _editButton.frame.size.height)];
    [_deleteBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [_deleteBtn addTarget:self action:@selector(deleteAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_deleteBtn];
//向左轻扫
  UISwipeGestureRecognizer *leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftRecognizerThisCell:)];
    leftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
    [self.subView addGestureRecognizer:leftRecognizer];

    //向右轻扫
    UISwipeGestureRecognizer *rightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightRecognizerThisCell:)];
    rightRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
    [self.subView addGestureRecognizer:rightRecognizer];

    //点击
    UITapGestureRecognizer *pan = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(panRecognizerThisCell:)];
    [self.subView addGestureRecognizer:pan];
//手势的触发

//向左轻扫时手势添加的这个view左移动
- (void)leftRecognizerThisCell:(UIGestureRecognizer *)gesture
{
    UIView *view = gesture.view;
    [UIView animateWithDuration:0.2 animations:^{
        view.frame = CGRectMake(-46, _subView.frame.origin.y, _subView.frame.size.width, _subView.frame.size.height);
        _isLeft = YES;
    }];
}

//向右轻扫时手势添加的这个view右移动
- (void)rightRecognizerThisCell:(UIGestureRecognizer *)gesture
{
    UIView *view = gesture.view;
    if (_isLeft) {
        [UIView animateWithDuration:0.2 animations:^{
            view.frame = CGRectMake(0, 0, _subView.frame.size.width, _subView.frame.size.height);
            _isLeft = NO;
        }];
    }
}

//点击时,先判断此时的状态
- (void)panRecognizerThisCell:(UIPanGestureRecognizer *)gesture
{
    if (_isLeft) {
        [self rightRecognizerThisCell:gesture];
    } else {
        [self leftRecognizerThisCell:gesture];
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值