ios – UITableView滑动手势与UITableViewCell滑动冲突

前端之家收集整理的这篇文章主要介绍了ios – UITableView滑动手势与UITableViewCell滑动冲突前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
以下是我编写的用于在UITableView上放置2个手指滑动的代码
UISwipeGestureRecognizer *leftSwipe = [UISwipeGestureRecognizer new];
[leftSwipe addTarget:self action:@selector(nextDay)];
leftSwipe.numberOfTouchesrequired = 2;
leftSwipe.direction = UISwipeGestureRecognizerDirectionLeft;
leftSwipe.delegate = self;
[leftSwipe setCancelsTouchesInView:YES];
[tableViewTasks addGestureRecognizer:leftSwipe];

UISwipeGestureRecognizer *rightSwipe = [UISwipeGestureRecognizer new];
[rightSwipe addTarget:self action:@selector(prevIoUsDay)];
rightSwipe.numberOfTouchesrequired = 2;
rightSwipe.direction = UISwipeGestureRecognizerDirectionRight;
rightSwipe.delegate = self;
[rightSwipe setCancelsTouchesInView:YES];
[tableViewTasks addGestureRecognizer:rightSwipe];

我正在使用SWTableViewCell左右(单击)gestureRecognisers.
当使用2个手指向左/向右滑动UITableView时,SWTableViewCell左右手势也会在此之后被触发.
如何制止冲突?

解决方法

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    if (SWTableViewCellTouch) {
        SWTableViewCellTouch = NO
        return NO;
    }

    return YES;
}

当您触摸SWTableViewCell时,将BOOL SWTableViewCellTouch设置为YES.

猜你在找的iOS相关文章