[英]How to add a UILongPressGestureRecognizer to a UITextField?
[英]How to add UILongPressGestureRecognizer to a UITextField?
我正在尝试将UILongPressGestureRecognizer
添加到页面上的UITextField之一,但是当长按UiTextField时它不会调用选择器方法。 我将它添加到UItextField但是当我长按TextField但在场上显示放大镜时它不会调用Selector方法。
[self.tfCustomerStreet addGestureRecognizer:LongPressgesture];
但它工作正常并调用选择器方法,如果我将其添加到视图。
[[self view] addGestureRecognizer:LongPressgesture];
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一起使用。
如果删除[LongPressgesture setMinimumPressDuration:2.0];
它会起作用..因为将调用标签手势来开始编辑textField ...或者只是实现这个手势委托功能
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
保证允许同时识别此方法返回YES。
请享用 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.