tableViewcell上进行手势的添加

来源:互联网 发布:蜘蛛池外推软件 编辑:程序博客网 时间:2024/05/16 15:16

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

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

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
原创粉丝点击