UIGestureRecognizer full view

I want the gesture recognizer to listen to two fingers anywhere on the screen.

Right now I have a UITableView in a subtask that scrolls, of course, and it doesn't seem to pick up the UIGestureRecognizer that I set in the view. When you use two fingers, it just scrolls ...

Is there a way to make the whole look, perhaps a supervisor, listen to the touch of two fingers and when it recognizes it, instead of scrolling through the table view, do what I want?

EDIT : Heres my code, but this is considered a very general question. I just want to have UIGestureRecognizers in all appearance, all this.

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]; 
+6
source share
5 answers

Perhaps I did not clearly explain my question. But for what I did, it worked, and perhaps it will help other people in the future:

Two-finger swipe in UIScrollview for iPad

+4
source

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 this helps

+2
source
 //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... } } 

Hope this solves your problem. and when the touch is on, make the score equal to 2 or any number of touches .. :) do not hesitate to ask if you have any doubts.

+2
source

Add another view with the self.view frame above self.view, like "viewForGesture", and add a gesture recognizer to this view, for example

  UIView *viewForGesture = [[ [UIView alloc]initWithFrame:self.view.frame] autorelease]; [viewForGesture setBackgroundColor:[UIColor clearColor]]; [self.view addSubview:viewForGesture]; . . . [viewForGesture addGestureRecognizer:swipeOpen]; [viewForGesture addGestureRecognizer:swipeClose]; 
+1
source

There are two ways to make UIView touch detection. The approach that you have defined and want UIGestureRecognizer , this answer has already been given by Ezeki. Another approach you can use to detect touch is to override UITouch delegates.

 - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; if(touch.tapCount==2) { //Do something ... (Here, you can also check for the object which touched.) } } 
0
source

Source: https://habr.com/ru/post/927601/


All Articles