Gesture Recognizers and TableView

前端 未结 3 382
日久生厌
日久生厌 2021-02-02 17:13

I have a UIView which covers all of a UITableView. The UIView is using gesture recognizers for control of what the table displays. I still need the vertical UITableView scrollin

3条回答
  •  失恋的感觉
    2021-02-02 17:57

    Assign your gesture to the table view and the table will take care of it:

    UISwipeGestureRecognizer *gesture = [[UISwipeGestureRecognizer alloc]
            initWithTarget:self action:@selector(handleSwipeFrom:)];
    [gesture setDirection:
            (UISwipeGestureRecognizerDirectionLeft
            |UISwipeGestureRecognizerDirectionRight)];
    [tableView addGestureRecognizer:gesture];
    [gesture release];
    

    Then in your gesture action method, act based on the direction:

    - (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
        if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) {
            [self moveLeftColumnButtonPressed:nil];
        }
        else if (recognizer.direction == UISwipeGestureRecognizerDirectionRight) {
            [self moveRightColumnButtonPressed:nil];
        }
    }
    

    The table will only pass you the gestures you have asked for after handling them internally.

提交回复
热议问题