排除长按识别器的特定区域

Exclude specific area for long tap recognizer

我有一个方法可以在我的集合视图单元格的左上角添加按钮,以及长按识别器。问题是,当我将 longPressRecognizer minimumPressDuration 设置为 0.0001 之类的值时,我无法点击按钮,因为点击按钮不会激活 longPressRecognizer 方法。请看:

    UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];

[[RACObserve(self, shouldEdit) deliverOnMainThread] subscribeNext:^(id x) {

    UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];
    if (self.shouldEdit){

        self.layout.longPressGestureRecognizer.minimumPressDuration = 0.1;

        int ind = indexPath.row;
        NSLog(@"1 blk called");
    button = [UIButton buttonWithType:UIButtonTypeContactAdd];
    [button addTarget:self
               action:@selector(aMethod:)
     forControlEvents:UIControlEventTouchUpInside];
    [button setTag:indexPath.row];
    [cell addSubview:button];

    [button mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.equalTo(cell.mas_left).with.offset(0);
        make.top.equalTo(cell.mas_top).with.offset(0);
        make.width.height.equalTo(@(20));

    }];

    }

我使用反应式 cocoa 和砌体,但这实际上并不重要,我想要的是从区域中排除按钮区域,我可以将其用于 longGestureRecognizer.

self.layout.longPressGestureRecognizer.minimumPressDuration = 0.1;

你可以使用 self.myview.longPressGestureRecognizer.minimumPressDuration = 0.1;在我看来,不要将按钮放在 myview.by 中,您可以点击按钮