以下是我编写的用于在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.