iPhone iOS如何将UILongPressGestureRecognizer和UITapGestureRecognizer添加到同一控件并防止冲突? [英] iPhone iOS how to add a UILongPressGestureRecognizer and UITapGestureRecognizer to the same control and prevent conflict?

查看:792
本文介绍了iPhone iOS如何将UILongPressGestureRecognizer和UITapGestureRecognizer添加到同一控件并防止冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个iPhone应用程序,让用户重新排列屏幕上的一些UI元素。

I'm building an iPhone app that would let the user rearrange some of the UI elements on the screen.

如何在同一个UIView中添加轻击手势识别器和长按手势识别器?当我从长按中抬起手指时,轻敲手势识别器会触发。如何在用户执行长按时暂时禁用点击手势识别器或阻止其触发?

How can I add a tap gesture recognizer and a long press gesture recognizer to the same UIView? When I lift up the finger from the long press, the tap gesture recognizer fires. How can I temporarily disable the tap gesture recognizer or prevent it from firing when the user is performing a long press?

谢谢!

推荐答案

要允许两个手势一起使用,请实现以下委托方法:

To allow both gestures to work together, implement the following delegate method:

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

为了使长按具有第一优先权,请执行:

To make it so that the long press has first priority, do:

[tapGesture requireGestureRecognizerToFail:longPress];

这篇关于iPhone iOS如何将UILongPressGestureRecognizer和UITapGestureRecognizer添加到同一控件并防止冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆