I want to be able to make a gesture recognizer listening for a two finger swipe, anywhere on the screen.
Right now I have a UITableView in a sub-view that scrolls, of course, and it doesn't seem to pick up the UIGestureRecognizer that I set on the view. When you use the two fingers, it just scrolls...
Is there a way to make the entire view, maybe superview, listen for a two finger touch and when it recognizes it, it will instead of scrolling the table view, do what I want it to do?
EDIT: Heres my code but this is suposed to be a very general question. I just want to be able to have UIGestureRecognizers across the entire view, the whole thing.
navBarTitle.title = @"Crunch";
//opening the menuView from launch
//setup the customtable view as a subview in menuView
SDMenuViewController *mvc = [[[SDMenuViewController alloc] initWithNibName:@"SDNestedTableView" bundle:nil] autorelease];
[self addChildViewController:mvc];
[mvc didMoveToParentViewController:self];
[menuView addSubview:mvc.view];
[mvc.view setFrame:CGRectMake(mvc.view.frame.origin.x, mvc.view.frame.origin.y, mvc.view.frame.size.width, mvc.view.frame.size.height + 44)]; //add navBarHeight, for some strage reason
//add swipe down gesture on for the menu
UISwipeGestureRecognizer *swipeClose =[[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(closeMenu)] autorelease];
 swipeClose.numberOfTouchesRequired = 2;
 swipeClose.direction = UISwipeGestureRecognizerDirectionUp;
 UISwipeGestureRecognizer *swipeOpen = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(openMenu)] autorelease];
 swipeOpen.numberOfTouchesRequired = 2;
 swipeOpen.direction = UISwipeGestureRecognizerDirectionDown;
for (UIGestureRecognizer* rec in menuView.gestureRecognizers) {
    [rec requireGestureRecognizerToFail:swipeClose];
    [rec requireGestureRecognizerToFail:swipeOpen];
}
for (UIGestureRecognizer* rec in mvc.view.gestureRecognizers) {
    [rec requireGestureRecognizerToFail:swipeClose];
    [rec requireGestureRecognizerToFail:swipeOpen];
}
[mvc.view addGestureRecognizer:swipeClose];
[mvc.view addGestureRecognizer:swipeOpen];
[self.view addGestureRecognizer:swipeClose];
[self.view addGestureRecognizer:swipeOpen];
Maybe I did not explain my question clearly. But for what I was doing this ended up working, and maybe it will help other people in the future:
Two finger swipe in UIScrollview for iPad application
you can try to do something like this:
UISwipeGestureRecognizer* p = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(actionPan:)];
p.numberOfTouchesRequired = 2;
for (UIGestureRecognizer* rec in tableView.gestureRecognizers) {
    [rec requireGestureRecognizerToFail:p];
}
[self.view addGestureRecognizer:p];
hope that will help
//In view did load        
    [self.view setMultipleTouchEnabled:YES];
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if ([[event touchesForView:self.view] count] > 1) {
        NSLog(@"%d active touches",[[event touchesForView:self.view] count]) ;
 UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
            swipeGesture.direction = UISwipeGestureRecognizerDirectionUp;
            [self.view addGestureRecognizer:swipeGesture];
  }
}
    -(void)handleSwipeGesture:(UISwipeGestureRecognizer *) sender 
    {
        //Gesture detect - swipe up/down , can be recognized direction
        if(sender.direction == UISwipeGestureRecognizerDirectionUp)
        {
            // do some thing...
        }
    }
i Hope this would solve your problem. and in touches enabled make the count equal to 2 or any number of touches.. :) feel free to ask if you have any doubts
Add another view with frame of self.view over self.view like "viewForGesture" and add gesture recognizer on that view like
       UIView *viewForGesture = [[ [UIView alloc]initWithFrame:self.view.frame] autorelease];
       [viewForGesture setBackgroundColor:[UIColor clearColor]];
       [self.view addSubview:viewForGesture];
        .
        .
        .
       [viewForGesture addGestureRecognizer:swipeOpen];
       [viewForGesture addGestureRecognizer:swipeClose];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With