UIGestureRecognizer blocks subview for handling touch events

后端 未结 10 1065
北恋
北恋 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:07

    I was displaying a dropdown subview that had its own tableview. As a result, the touch.view would sometimes return classes like UITableViewCell. I had to step through the superclass(es) to ensure it was the subclass I thought it was:

    -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
    {
        UIView *view = touch.view;
        while (view.class != UIView.class) {
            // Check if superclass is of type dropdown
            if (view.class == dropDown.class) { // dropDown is an ivar; replace with your own
                NSLog(@"Is of type dropdown; returning NO");
                return NO;
            } else {
                view = view.superview;
            }
        }
    
        return YES;
    }
    

提交回复
热议问题