且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

手势识别器和 TableView

更新时间:2023-01-25 14:05:37

将你的手势分配给 table view,table 会处理它:

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.