2

在我的应用程序中,我有以下代码:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)recognizer shouldReceiveTouch:(UITouch *)touch
{

    if ([touch.view isKindOfClass:[UIScrollView class]]){
        return YES;
    }

    else return NO;
}

在此我控制我的触摸是否在滚动视图内,但现在我想检查触摸是简单触摸还是滑动手势,有没有办法检测到它?谢谢

4

3 回答 3

8

你上面写的方法是UIGestureRecognizerDelegate。这是一个委托方法,当您放置观察者的特定手势被检测到时,将被调用。

为了识别滑动手势,您必须将手势识别器添加到要检测的视图中,如下所示:

UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[[self view] addGestureRecognizer:recognizer];
[recognizer release];

您可以在方法handleSwipeForm 中获得手势检测:

如果你想让上面的委托被调用,那么还要添加这一行,

recognizer.delegate = self;
于 2013-01-24T10:09:24.723 回答
0

用于UISwipeGestureRecognizer检测滑动手势(可以设置滑动方向 UISwipeGestureRecognizer.direction:)

和一个UITapGestureRecognizer检测点击(UITapGestureRecognizer.numberOfTapsRequired设置触发识别器所需的点击次数(例如双击)

于 2013-01-24T10:03:00.910 回答
0

您必须使用 UISwipeGestureRecognizer 来检测滑动手势。

 UISwipeGestureRecognizer *swipeGest= [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(SwipeRecognizer:)];
[swipeGest setDirection:(UISwipeGestureRecognizerDirectionRight)];
[[self view] addGestureRecognizer:swipeGest];
swipeGest.delegate = self;

setDirection 用于设置滑动检测方向。

- (void)SwipeRecognizer:(UIGestureRecognizer *)gestureRecognizer
{
}

在这里,我们将编写检测到滑动手势后要执行的函数。

于 2015-05-20T14:13:58.557 回答