search

Home  >  Q&A  >  body text

objective-c - I would like to ask which method to intercept if I want to monitor the Tap click event of UIView?

When intercepting UIButton events, I know that the sendAction:to:forEvent: method will be executed after the button is clicked, so I can hook this method to do other things. So which method should I intercept for the UIView's Tap event?

我想大声告诉你我想大声告诉你2837 days ago600

reply all(1)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-02 09:27:02

    The tap event added by the following code

    self.backgroundTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleBackgroundTapGesture:)];
    self.backgroundTapRecognizer.delegate = self;
    [self.maskView addGestureRecognizer:self.backgroundTapRecognizer];

    Can be intercepted with shouldReceiveTouch

    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
    {
        if ([touch.view isDescendantOfView:self.popupView]) { //判断条件,比如是popView
        //NSLog(@"NO");
            return NO; //点击无效
        }
        return YES;
    }

    reply
    0
  • Cancelreply