UIGestureRecognizer blocks subview for handling touch events

后端 未结 10 1045
北恋
北恋 2020-11-28 19:32

I\'m trying to figure out how this is done the right way. I\'ve tried to depict the situation: \"enter

10条回答
  •  温柔的废话
    2020-11-28 20:05

    It is possible to do without inherit any class.

    you can check gestureRecognizers in gesture's callback selector

    if view.gestureRecognizers not contains your gestureRecognizer,just ignore it

    for example

    - (void)viewDidLoad
    {
        UITapGestureRecognizer *singleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self     action:@selector(handleSingleTap:)];
        singleTapGesture.numberOfTapsRequired = 1;
    }
    

    check view.gestureRecognizers here

    - (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer
    {
        UIEvent *event = [[UIEvent alloc] init];
        CGPoint location = [gestureRecognizer locationInView:self.view];
    
        //check actually view you hit via hitTest
        UIView *view = [self.view hitTest:location withEvent:event];
    
        if ([view.gestureRecognizers containsObject:gestureRecognizer]) {
            //your UIView
            //do something
        }
        else {
            //your UITableView or some thing else...
            //ignore
        }
    }
    

提交回复
热议问题