2021-01-22

UITableViewCell内加入UIPanGestureRecognizer时,当在cell上下滑动tableView时发现没有响应。可以在

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer

locationInView:获取到的是手指点击屏幕实时的坐标点;
translationInView:获取到的是手指移动后,在相对坐标中的偏移量

代理方法内判断滑动方向。如果为上下滑动,返回NO,否则返回YES

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {

    UIPanGestureRecognizer *pan = (UIPanGestureRecognizer *)gestureRecognizer;
    CGPoint transLcation = [pan translationInView:view];
    
    CGFloat absX = fabs(transLcation.x);
    CGFloat absY = fabs(transLcation.y);

    if (absY > absX) {
        return NO;
    }
    
    return YES;
}

你可能感兴趣的:(2021-01-22)