ios - UILongPressGestureRecognizer 和 UITextField 不能一起工作

标签 ios uitextfield uigesturerecognizer

我有一个带有 LongPressGesturerecognizer 的 UIViewController。 View Controller View 中还有一个 UITextField。

如果我点击 UITextField,Gesturerecognizer 会捕获长按。无法复制、粘贴、移动光标。

我想让 Gesturerecognizer 在 View 中的任何地方都处于事件状态,但 UITextField 除外,我希望在 UITextField 中使用默认的操作系统行为,如复制、粘贴、移动光标等。

这可能吗?我能以某种方式告诉手势识别器将手势转发到 UITextFields 默认值吗?

最佳答案

您必须为您的 UILongPressGestureRecognizer 设置委托(delegate)并实现 gestureRecognizer:shouldReceiveTouch: 委托(delegate)方法,如下所示:

- (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    return touch.view != self.textField;
}

关于ios - UILongPressGestureRecognizer 和 UITextField 不能一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12786749/

相关文章:

ios - 在静态 TableView 中使用开关

c# - 使用 C# 在 iPhone 上提示 UITextField

iphone - 当 UITextField 成为 FirstResponder 时得到通知

ios - UIGestureRecognizer 方法说明

ios - 如何在 Swift5 的 App Store 中检查我的应用程序是否有新版本?

IOS取消本地通知

ios - 将值作为参数从 View Controller 传递到实体类的方法

iphone - 输入文本到点击的 UILabel?

ios - 禁用手势识别器

ios - iOS app开发,是否可以检测相机是否拍过照片?