【发布时间】:2014-08-03 10:30:49
【问题描述】:
我向整个视图添加了向上滑动手势。
我在整个视图中添加了一个 longPressGestureRecognizer,设置它的 minimunPressDuration 等于 0.001f 以便它可以检测按下动作和触摸移动动作,然后调用 requireGestureToFail 函数:
UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressed:)]; longPressGestureRecognizer.minimumPressDuration = 0.001f; [longPressGestureRecognizer requireGestureRecognizerToFail:swipeGestureRecognizer];
问题是:
当用户按住(不要移动)按钮时,长按手势的状态保持为 UIGestureStatePossible 因为向上滑动手势不会失败,因此它不会对用户触摸做出反应。
如果我不调用 requireGestureRecognizerToFail 所有手势,包括 swipeUp 手势,都将被识别为 longPress 手势。
实现 shouldRecognizeSimultaneouslyWithGestureRecognizer: 不是我所期望的。
我想要的是当按住(不要移动)一个按钮时,它会触发 longPress,然后如果用户向上滑动它会触发 swipeUp 手势,如果用户拖动但触摸模式不适合 swipeUp 它仍然会触发 longPress .
我该如何实现?
【问题讨论】:
-
你试过倒车吗?也许滑动应该需要长按才能失败。
-
谢谢,但它不起作用。尽管如此,所有手势都被识别为 longPress。
标签: ios objective-c