仅在不滑动时拖动

时间:2014-05-28 02:15:15

标签: uigesturerecognizer swipe drag

我有UIView,我希望用户能够在屏幕上拖动。但是,如果在同一个UIView中向上滑动,也会发生一个特定的操作。现在,我有一个附加到UIView的Swipe Up Gesture识别器,我实现了touchesBegan,touchesMoved和touchesEnded方法。一切正常,除了一个问题,当用户向上滑动时,UIView首先上升一点,然后Gesture Recognizer接管并完成向上滑动操作。是否有一种方法可以延迟拖动一瞬间,直到用于向上滑动的Gesture识别器失败,然后touchesBegan,touchesMoved和touchesEnded接管并按常规操作?

感谢。

1 个答案:

答案 0 :(得分:0)

我会删除touches *方法并用平移手势识别器替换它们。然后,您可以要求在平移手势动作之前滑动手势失败。您可以实现以下行为:

[self.panRecognizer requireGestureRecognizerToFail:self.swipeRecognizer];

正如Apple https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizer_basics/GestureRecognizer_basics.html

所建议的那样

编辑作为替代方案,您可以修改touchesMoved,这样只有当您的滑动识别器的状态为“UIGestureRecognizerStateFailed”时,它才会移动您的视图,这会给您相同的行为但不需要您修改太多代码。