简体   繁体   English

在同一视图上点击并滑动手势

[英]Tap and swipe gesture on same view

I have two gesture tap and swipe on same view. 我有两个手势点击并在同一视图上滑动。 Whenever user tries to swipe the view, tapGesture gets recognise. 每当用户尝试滑动视图时,tapGesture都会被识别。 I want tap to be ignored in this case. 我想在这种情况下忽略水龙头。 How to do that. 怎么做。 Below is the code. 下面是代码。 This is not the case of simultaneous recogniser because swipe gesture is not getting called. 同时识别器不是这种情况,因为不会调用滑动手势。

     UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(itemSelected:)];
     gest.numberOfTapsRequired = 1
     [messageView addGestureRecognizer:gest];

    UISwipeGestureRecognizer *swipeGest = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(itemSwiped:)];
    swipeGest.direction =  UISwipeGestureRecognizerDirectionUp ;
    [messageView addGestureRecognizer:swipeGest];

While the suggested answer is fine, a simpler solution might be to require the tap gesture to wait for the swipe gesture to fail using - (void)requireGestureRecognizerToFail:(UIGestureRecognizer *)otherGestureRecognizer . 虽然建议的答案很好,但更简单的解决方案可能是要求使用- (void)requireGestureRecognizerToFail:(UIGestureRecognizer *)otherGestureRecognizer来要求轻击手势等待滑动手势失败。 This method "creates a relationship with another gesture recognizer that delays the receiver's transition out of UIGestureRecognizerStatePossible ." 此方法“与另一个手势识别器建立关系,从而延迟接收者从UIGestureRecognizerStatePossible过渡出来。” In your case, the code would look like: 在您的情况下,代码如下所示:

[gest requireGestureRecognizerToFail:swipeGest];

You can find more information here . 您可以在此处找到更多信息。

In your handlers itemSelected and itemSwiped , be sure that you are checking the state of the UIGestureRecognizer . 确保在处理程序itemSelecteditemSwiped ,正在检查UIGestureRecognizerstate

Possible states include: possible , began , changed , ended , cancelled , and failed . 可能的状态包括: possiblebeganchangedendedcancelledfailed

You should likely be looking for the ended state. 您可能应该在寻找ended状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM