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

标签 ios objective-c uigesturerecognizer

我有一个方法可以在我的 Collection View 单元格的左上角添加按钮,以及长按识别器。问题是,当我将 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));

    }];

    }

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

最佳答案

self.layout.longPressGestureRecognizer.minimumPressDuration = 0.1;

你可以使用 self.myview.longPressGestureRecognizer.minimumPressDuration = 0.1;并且在我的 View 中不要在我的 View 中放置按钮。这样你就可以点击按钮

关于ios - 排除长按识别器的特定区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36836734/

相关文章:

ios - 为什么我总是必须将 Sprite 的位置更改为其他位置才能获得所需的工作位置

ios - Xcode运行脚本删除文件夹中的所有文件

javascript - android webview中的水平分页就像ios一样

ios - 类型 'NSPersistentStore' 在 swift 中不符合协议(protocol) 'BooleanType'

ios - 如何创建可扩展的 UITableView 部分?

ios:如何使 UIPickerView(UIView) 在 UITouchRecognizer 之前捕获触摸事件?

ios - objective-c plist 尾随零

iphone - 如何调整 UIToolBar 左右内边距

ios - 由于UITapGestureRecognizer无法调用didSelectRowAtIndexPath

ios - 将 Pan UIGesture 转换为滑动手势