I have a scenario like shown below
Right now, I am showing only 1 view with label 8. But I am planning to add 3 more such views to the HolderView.
The SmallerView/s are created from other Nib files.
I did this code for adding Tap Recognizer for ViewController's view
UITapGestureRecognizer *tapRecognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapRecognized2:)];
[tapRecognizer setDelegate:self];
[self.view addGestureRecognizer:tapRecognizer];
Code for adding Tap Recognizer to the smaller views I added smaller views to the HolderView. And assigned Tag IDs to them. After that,
for (SmallerView *view in HolderView.subviews) {
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecognized:)];
[recognizer setDelegate:self];
NSLog(@"Added gesture to the view with tag: %ld",view.tag);
[view addGestureRecognizer:recognizer];
}
3. - (void)tapRecognized:(UITapGestureRecognizer *)paramSender { NSLog(@"tapped on %ld", paramSender.view.tag); }
- (void)tapRecognized2:(UITapGestureRecognizer *)paramSender
{
NSLog(@"VC view");
}
- I have enabled UserInteraction (both in code and Inspector) for all the views and UILabels on smaller views too.
The problem now is... The smaller view's Tap recognisers are not really working consistently. Sometimes they print the output. All at suddenly it prints the ViewController's recogniser's output. Please help
UPDATE: Below is my View diagram. Green Border: (In UIView's initWithFrame)d
self.layer.borderColor = [UIColor greenColor].CGColor;
Red Border:
MyTile *tile = [[[NSBundle mainBundle] loadNibNamed:@"View" owner:self options:nil] objectAtIndex:0];
self.myLabel.layer.borderColor=[UIColor redColor].CGColor;
Why that Green Border is coming only of that size? Shouldn't that be full square? And, the gesture works only when I tap on the green area. Why?