How to have a UISwipeGestureRecognizer AND UIPanGestureRecognizer work on the same view

后端 未结 4 1116
春和景丽
春和景丽 2020-12-04 19:58

How would you setup the gesture recognizers so that you could have a UISwipeGestureRecognizer and a UIPanGestureRecognizer work at the same

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 20:26

    You're going to want to set one of the two UIGestureRecognizer's delegates to an object that makes sense (likely self) then listen, and return YES for this method:

    - (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
             shouldRecognizeSimultaneouslyWithGestureRecognizer:
                                (UIGestureRecognizer *)otherGestureRecognizer {
        return YES;
    }
    

    This method is called when recognition of a gesture by either gestureRecognizer or otherGestureRecognizer would block the other gesture recognizer from recognizing its gesture. Note that returning YES is guaranteed to allow simultaneous recognition; returning NO, on the other hand, is not guaranteed to prevent simultaneous recognition because the other gesture recognizer's delegate may return YES.

提交回复
热议问题