如何识别从左到右的滑动动作?

时间:2012-09-07 20:59:39

标签: objective-c ios uigesturerecognizer

如果我正在尝试识别向左或向右或从左到右的滑动动作。我是否需要使用UISwipeGestureRecognizer UISwipeGestureRecognizerDirectionLeft方向,然后动态添加UISwipeGestureRecognizer方向的UISwipeGestureRecognizerDirectionRight

然后当用户抬起手指时,我会用UISwipeGestureRecognizerDirectionRight方向移除手势识别器?

1 个答案:

答案 0 :(得分:2)

如果我正确理解你,你只想检测一个从左到右的手势,你只需要使用UISwipeGestureRecognizerDirectionRight。这是一个例子:

UISwipeGestureRecognizer *swipeLeftToRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(myMethod:)];
[swipeLeftToRight setDirection:UISwipeGestureRecognizerDirectionRight];
[swipeLeftToRight setDelegate:self];
[someView addGestureRecognizer:swipeLeftToRight];