I have two UIbuttons,and I want to implement Longpressgesture on both.
So I wrote the below code..
-(void)viewdidLoad
{
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(buttonLongPressed:)];
longPress.minimumPressDuration = 0.5;
[Button1 addGestureRecognizer:longPress];
[Button2 addGestureRecognizer:longPress];
}
- (void)buttonLongPressed:(UILongPressGestureRecognizer *)sender
{
if(sender.state == UIGestureRecognizerStateBegan)
{
}
}
now my doubt is how shall I check which button is longpresses?
Thanks
Ranjit
First, note that a gesture recognizer should be attached to just one view. You should create a new instance for each button.
To answer your question, you can add tag values to your buttons:
Then test them in the recognizer:
You can enter any tag values, but I often start at a high value like 1000 to avoid clashes with any other tags that I assign in Interface Builder.
Another option is to use a different handling function for each recognizer.