How to add UILongPressGestureRecognizer to a UITextField?
ios, ipad, iphone, objective-c, uitextfield
Solution
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;
}
returning YES to this method is guaranteed to allow simultaneous recognition.
Enjoy :)
Problem
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]; ``` But it works fine and call the selector 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 do I make it work with UITextField.