On my UIViewController I have different UIViews, and some of them are my custom UIViews. How to know which UIView was touched, my custom or not ??
Asked
Active
Viewed 371 times
2 Answers
2
You can set tag to each of your view.
view1.tag = y;
UITapGestureRecognizer *tapGesture =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(singleTapGestureCaptured:)];
tapGesture.numberOfTapsRequired = 1;
[view1 addGestureRecognizer:tapGesture];
and in singleTapGestureCaptured method:
- (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture
{
[[gesture view] tag];
NSLog(@"tap captured for view :%d", [[gesture view] tag]);
}
coverback
- 4,364
- 1
- 17
- 30
Abdullah Md. Zubair
- 3,327
- 2
- 29
- 38
1
You can create two UIGestureRecognizers then you have to associate the gesture recognizer with your views like this:
UITapGestureRecognizer * recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[view addGestureRecognizer:recognizer];
UITapGestureRecognizer * recognizerCustom = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapCustom:)];
[customView addGestureRecognizer:recognizer];
This way you know when the handleTap: method is called your normal view was touched and when your handleTapCustom: gets called your custom view was called.
Oscar Gomez
- 18,248
- 12
- 81
- 116