UIView上添加了一个按钮和一个单击手势的事件相应,互相不影响的处理方法。。

时间:2024-04-27 23:06:59
tapGesture.delegate = self;

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

{

    CGPoint location = [touch locationInView:self.view];

    if(CGRectContainsPoint(button.frame, location))

    {

        return NO;

    }

    return YES;

}

响应如上委托方法,判断,手势的触击方法是否在按钮区域,如果是,则返回NO,禁用手势。否则返回YES