UILongPressGestureRecognizer с разными кнопками - PullRequest
1 голос
/ 13 февраля 2012

У меня есть 2 кнопки с «UILongPressGestureRecognizer», чтобы сделать это, я делаю:

Кнопка FOT 1:

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

Для кнопки 2:

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

И в "longpressGesture" мне нужно различать button1 и button2, но я не могу этого сделать ...

 - (void)longPressHandler:(UILongPressGestureRecognizer *)gestureRecognizer{//Here i need do the differentation}

Спасибо за все!

С уважением.

1 Ответ

6 голосов
/ 13 февраля 2012

Что вы можете сделать, это использовать view свойство UIGestureRecognizer, поэтому, если вы сохраните ссылку на обе ваши кнопки, вы можете проверить равенство.

Так что если у вас есть

@interface blah
{
  UIButton *buttonOne;
  UIButton *buttonTwo;
}

затем вы добавляете распознаватели к кнопкам, которые вы можете сделать в обработчике

if(gestureRecognizer.view==buttonOne)
{
   //do stuff for button one
}
else if(gestureRecognizer.view==buttonTwo)
{
  //do stuff for button two
}

надеюсь, это поможет

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...