ios 侧滑菜单与侧滑删除手势冲突问题

用的侧滑菜单库是:CWLateralSlide

在使用这个库后,侧滑菜单正常, 但是侧滑删除就失效了,这是因为,侧滑菜单的手势和侧滑删除的手势冲突了, 解决办法是:

进入到CWInteractiveTransition.m文件看到

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {

    if ([[self viewController:otherGestureRecognizer.view] isKindOfClass:                              [UITableViewController class]]) {

        return YES;

    }

    return NO;

}


可以看出在这个方法中是手势响应的关键.

解决方案:

在这里只要把tableviewCellcontentView手势响应置为yes就可以了.因为我是用pod导入的库,不想在原码中改,就为CWInteractiveTransition类添加类别, 在类别的.m文件中重写了一下两个方法:

- (UIViewController *)viewController:(UIView *)view{

   for (UIView* next = view; next; next = next.superview) {

        UIResponder* nextResponder = [next nextResponder];

        if ([nextResponder isKindOfClass:[UIViewController class]]) {

            return (UIViewController*)nextResponder;

        }

    }

    return nil;

}

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {

    if ([[otherGestureRecognizer.view superview] isKindOfClass:[UITableViewCell class]]) {

        return YES;

    }

    if ([otherGestureRecognizer.view isKindOfClass:[UITableView class]]) {

        return YES;

    }

    if ([[self viewController:otherGestureRecognizer.view] isKindOfClass:[UITableViewController class]]) {

        return YES;

 }

    return NO;

}

引入类别, 再次运行就可以了

结果 在ios 11之前的系统又出现问题 侧滑删除非常不灵敏, 最终将上面第二个方法用下面的方法替换得到完美解决

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {

        return gestureRecognizer.state != 0 ? YES : NO;

  }

你可能感兴趣的:(ios 侧滑菜单与侧滑删除手势冲突问题)