如何将UILongPressGestureRecognizer添加到UITextField? [英] How to add UILongPressGestureRecognizer to a UITextField?

查看:108
本文介绍了如何将UILongPressGestureRecognizer添加到UITextField?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 UILongPressGestureRecognizer 添加到页面上的UITextField之一,但是当长按UiTextField时它不会调用选择器方法。
我将它添加到UItextField但是当我长按TextField但在场上显示放大镜时它没有调用Selector方法。

I am trying yo add UILongPressGestureRecognizer to one of UITextField on page but It does not call the selector method when Long Press the UiTextField. I added it to UItextField But it does not call the Selector method when I Long press the TextField but Showing the Magnifier on Field.

[self.tfCustomerStreet addGestureRecognizer:LongPressgesture];

但如果我将它添加到View中,它可以正常工作并调用选择器方法。

But it works fine and call the selector Method if I add it to the View.

[[self view] addGestureRecognizer:LongPressgesture];

ViewDidLoad中的初始化代码

Initialization code in ViewDidLoad

UILongPressGestureRecognizer *LongPressgesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(LongPressgesture:)];
    [LongPressgesture setMinimumPressDuration:2.0];

// Long press gesture reconizer
- (void)LongPressgesture:(UILongPressGestureRecognizer *)recognizer 
{
    if (recognizer.state == UIGestureRecognizerStateEnded) {
        NSLog(@"Long press Ended .................");
    }
    else {
        NSLog(@"Long press detected .....................");
    }        
}

请告诉我如何使其与UITextField一起使用。

Please tell me How do I make it work with UITextField.

推荐答案

如果你删除 [LongPressgesture setMinimumPressDuration:2.0]; 它会起作用..因为将调用标签手势以开始编辑textField ...或者只是实现此手势委托功能

if you remove the [LongPressgesture setMinimumPressDuration:2.0]; it will work .. since the tab gesture will be called to start edit the textField ... or just implement this gesture delegate function

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

保证此方法返回YES可以同时识别。

returning YES to this method is guaranteed to allow simultaneous recognition.

享受:)

这篇关于如何将UILongPressGestureRecognizer添加到UITextField?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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