4
votes

All.

In my iOS 8.0 app.

In a Parent Child View architecture. By this code...

[self addChildViewController:slideTableViewController];
[self.view addSubview:slideTableViewController.view];
[slideTableViewController didMoveToParentViewController:self];

I have implemented TapGesturerecognizer & PanGesturerecognizer on Base View Controller.

So, that it can recognise Pan(Dragging) and Tap. I need both gestures on my BaseView.

Just do not want Tap Gesture on SlideView. As I want to execute didSelectRowAtIndexpath method on child view,

Solution:

Answer for Question 1: Many StackOverflow answers have the same funda.. Disable Tap gesture when your touch encounters child view.

if([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]){
                if(CGRectContainsPoint(slideTableViewController.view.frame,[touch locationInView:self.view])){
                    return NO;
     }
}

Answer for Question 2:

How to determine Is it a PanGesture or TapGesture ?

For each gesture type the delegate method will call

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch

If you have implemented two gestures in your view, pan gesture and touch gesture,

This method will call 2 times, 1 time for pan gesture and 1 time for tap gesture.

So, in this method you can check like isKindOfClass method.

Thank you very much for helping......

enter image description here

5
Why not set gesture.enabled = NOBannings
@Bannings Its better to use userInterationEnabled property.user4657588
could you post the code of how you are adding the gesture recognizer? maybe you are adding it to the wrong viewCatalina T.
I am adding the Gesture Recognizer by Storyboarding.Arpit B Parekh
@ArpitParekh Just check [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]Bannings

5 Answers

4
votes

You can implement the gesture's delegate method in your baseViewController :

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizershouldReceiveTouch:(UITouch *)touch {
    return touch.view == self.view;
}

OR //If it is a Tap Gesture and Your touch intersects with a perticular View, For that we have this method.

if([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]){
                if(CGRectContainsPoint(slideTableViewController.view.frame,[touch locationInView:self.view])){
                    return NO;
     }
}
5
votes

Just set tapGesture.cancelsTouchesInView = YES;

0
votes

I have done this in UIViews I hope this could help you:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

UITouch *touch = [touches anyObject];
[touch locationInView:self.view];
if(touch.view == self.topView )
{
     //just return
}
if(touch.view == SOSTopView )
{
   //just return
}
}
0
votes

Looks like you should implement this method of UITableViewDelegate:

- (NSIndexPath *)tableView:(UITableView *)tableView
  willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // you can add some logic here
    return nil;
}

This will prevent from selecting any rows.

-1
votes

Isn't there a userInteractionEnabled property that you can make use of? So you could do the following:

slideTableViewController.userInterationEnabled = NO;