1

I am experiencing this strange behavior.

I create a clean project (view template), add a toolbar with a button and hook it up with an action. it works ;) BUT, then when I add a UITapGestureRecognizer to the view of my viewcontroller the toolbar button stops working. (It is pressed but its action is not called) When I add the UITapGestureRecognizer only the action linked to it is called. It is like uitapgesture recognizer view were hiding the toolbar but actually is not.

What is happening here? What am I missing?

- (IBAction)itemAction{
    NSLog(@"%s", _cmd);
    self.view.backgroundColor = [UIColor whiteColor];
}
- (void) tapAction{
    NSLog(@"%s", _cmd);
    self.view.backgroundColor = [UIColor greenColor];
}
- (void)viewWasTapped:(UITapGestureRecognizer *)recognizer{
    if (recognizer.state == UIGestureRecognizerStateRecognized) {
        [self tapAction];
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewWasTapped:)];
    [tapGestureRecognizer setNumberOfTapsRequired:1];
    [self.view addGestureRecognizer:tapGestureRecognizer];
    [tapGestureRecognizer release]; 
}

EDIT: the project source can be downloaded from here

Thanks in advance for any advice

Ignacio

nacho4d
  • 43,720
  • 45
  • 157
  • 240
  • Where's the confusion? Your tap gesture recognizer is handling the tap before the button can. – Lily Ballard Feb 15 '11 at 03:09
  • Yep, I know that but the view of the gesture recognizer is below the toolbar so it should not happen that way. Should it? – nacho4d Feb 15 '11 at 03:13

2 Answers2

0

I've encountered a similar problem, and found this answer quite helpful, especially because it allows selectively excluding the gesture recognizer based on the type of view that was touched.

Community
  • 1
  • 1
Amos Joshua
  • 1,601
  • 18
  • 25
0

Eventually I found the reason:

tapGestureRecognizer.cancelsTouchesInView = NO;
nacho4d
  • 43,720
  • 45
  • 157
  • 240