Alberto Juarez
Alberto Juarez

Reputation: 444

UILongPressGestureRecognizer only call the second time

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

Upvotes: 1

Views: 400

Answers (1)

Malek_Jundi
Malek_Jundi

Reputation: 6160

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.

Upvotes: 2

Related Questions