How to add UILongPressGestureRecognizer to UITextField?

I am trying to add a UILongPressGestureRecognizer to one of the UITextField on the page, but does not invoke the selection method when Long Press UiTextField. I added it to the UItextField. But it does not call the Selector method when I press TextField for a long time, but I display a magnifying glass in the field.

 [self.tfCustomerStreet addGestureRecognizer:LongPressgesture]; 

But it works fine and calls the selection method if I add it to the view.

 [[self view] addGestureRecognizer:LongPressgesture]; 

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 ....................."); } } 

Please tell me how to do this with UITextField.

+6
source share
1 answer

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

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

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

Enjoy :)

+8
source

Source: https://habr.com/ru/post/915184/


All Articles