UISwipeGestureRecognizerDirection 仅识别正确的手势

UISwipeGestureRecognizerDirection only Recognizes Right Gesture

我正在尝试向 UITableView 中的每个单元格添加左右滑动手势。但是,无论我在哪里看,似乎都没有人回答这个问题。使用推荐的当前解决方案,我没有输入正确的手势处理程序。

UISwipeGestureRecognizer* right = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRight:)];
right.direction = UISwipeGestureRecognizerDirectionRight;
[self.tableView addGestureRecognizer:right];


UISwipeGestureRecognizer* left = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeft:)];
left.direction = UISwipeGestureRecognizerDirectionLeft;
[self.tableView addGestureRecognizer:left];

我为我的解决方案创建了两个不同的手势识别器。但是,我永远看不到正确的 UIGestureRecognizer 的响应。我不明白为什么我从来没有看到正确的手势识别器只留下一个响应。

-(void)swipeLeft:(UISwipeGestureRecognizer*)gestureRecognizer
{ NSLog("You have swiped Left");
}
-(void)swipeRight:(UISwipeGestureRecognizer*)gestureRecognizer
{ NSLog("You have swiped right"); //Never Enter this handler
}

使用此代码...

swift希望大家不要介意。

override func viewDidLoad() {
    super.viewDidLoad()

    var swipeRight = UISwipeGestureRecognizer(target: self, action: "respondToSwipeGesture:")
    swipeRight.direction = UISwipeGestureRecognizerDirection.Right
    self.view.addGestureRecognizer(swipeRight)

    var swipeDown = UISwipeGestureRecognizer(target: self, action: "respondToSwipeGesture:")
    swipeDown.direction = UISwipeGestureRecognizerDirection.Down
    self.view.addGestureRecognizer(swipeDown)
}

func respondToSwipeGesture(gesture: UIGestureRecognizer) {

    if let swipeGesture = gesture as? UISwipeGestureRecognizer {

        switch swipeGesture.direction {
        case UISwipeGestureRecognizerDirection.Right:
            println("Swiped right")
        case UISwipeGestureRecognizerDirection.Down:
            println("Swiped down")
        default:
            break
        }
    }
}