美文网首页
tableview和手势冲突

tableview和手势冲突

作者: 梁苏珍 | 来源:发表于2018-04-24 17:34 被阅读0次

当表加载在滑动视图上时,给表的上下滑动添加手势

UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];

    [swipe setDirection:UISwipeGestureRecognizerDirectionDown];

    swipe.delegate = self;

    [cell addGestureRecognizer:swipe];

    UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];

    [swipeUp setDirection:UISwipeGestureRecognizerDirectionUp];

    swipeUp.delegate = self;

    [cell addGestureRecognizer:swipeUp];

-(void)swipe:(UISwipeGestureRecognizer*)swipe

{

    if (swipe.direction == UISwipeGestureRecognizerDirectionUp) {

        NSLog(@"上");

    }

    else{

        NSLog(@"下");

    }

}

//需要添加解决的冲突

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

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

        return YES;

    }

    return NO;

}

相关文章

网友评论

      本文标题:tableview和手势冲突

      本文链接:https://www.haomeiwen.com/subject/vpgjlftx.html