0

I have a main view controller class which contains a UIScrollView and a number of subviews like cards.

Each card is an object and it is covered with a UIButton. I want to detect a tap on the UIButton and want to disallow taps on multiple cards at a time.

jscs
  • 63,694
  • 13
  • 151
  • 195
Dimil T Mohan
  • 129
  • 2
  • 10

2 Answers2

0

I understand your question partially . See if following helpful :

In your scroll view :

 for (int i=0;i<array;i++)
 {
       UIButton *button=[[UIButton alloc]initWithFrame:CGRectMake(scrollWidth, 5,50,40)];
       button.userInteractionEnabled=YES;
       UITapGestureRecognizer *rcognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(buttonSelcted:)];
       [button addGestureRecognizer:rcognizer];
       [scrollView addSubview:button];
       scrollWidth=scrollWidth+80;
  }

In buttonSelected method just do following :

-(void)buttonSelected:(UITapGestureRecognizer *)recognizer
{
    UIButton *selectedItem=(UIButton*)recognizer.view;
    //do what you want with button
}
V-Xtreme
  • 7,230
  • 9
  • 39
  • 79
0

In all your buttons setExclusiveTouch on. As:

[button setExclusiveTouch:YES];

For further Details on it you can refer:

  1. exclusiveTouch
  2. Specifying Custom Touch Event Behavior
rptwsthi
  • 10,094
  • 10
  • 68
  • 109