Question

It is my problem, when i used UILongPressGestureRecognizer, it only works in the second time... I push 3 seconds the button and it dont work, but the second time that i push 3 second the button it works fine... Some idea?

-(IBAction)seleccionar1:(id)sender{
UILongPressGestureRecognizer *longpressGesture =[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)];
longpressGesture.minimumPressDuration = 3;
[longpressGesture setDelegate:self];
[sender addGestureRecognizer:longpressGesture];}

-(IBAction)seleccionar2:(id)sender{
UILongPressGestureRecognizer *longpressGesture =[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)];
longpressGesture.minimumPressDuration = 3;
[longpressGesture setDelegate:self];
[sender addGestureRecognizer:longpressGesture];}

- (void)longPressHandler:(UILongPressGestureRecognizer *)gestureRecognizer{
if(gestureRecognizer.view==boton1)
{
    [boton1 setTitle:@"Funciona 1" forState:UIControlStateNormal];
}
if(gestureRecognizer.view==boton2)
{
    [boton2 setTitle:@"Funciona 2" forState:UIControlStateNormal];
}}

Thanks for all friends.

Best regards

Was it helpful?

Solution

because in the first time the gesture is not added to the button you add it on the user action .. so add the gestures to the buttons before that for example in the viewDidLoad.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top