0

我有一个容器视图,上面有两个 UILongPressGestureRecognizers(不仅是这两个,而且其他手势都可以)。一个是识别一个手指,另一个是两个。当我尝试为一根手指触发手势时,它不会触发它的目标方法,直到手指抬起。两个手指的第二个手指按预期工作,在短时间内触发选择器动作。当我禁用两指按下的手势时,一指按下恢复正常。手势是如何初始化的,首先是一个手指手势,在vc setup里面初始化。

 - (void) setupGestures
{
    [self.contentView addGestureRecognizer:self.longGestureRecognizer];
}

- (UILongPressGestureRecognizer *)longGestureRecognizer
{
    if (!_longGestureRecognizer) {
        _longGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)];
        [_longGestureRecognizer setMinimumPressDuration:1];
    }
    return _longGestureRecognizer;
}

第二个是稍后初始化的,但不是来自主机 VC,而是添加到它的内部视图

//Called in host
rullerView = [[RullerView alloc] initWithContent:self.contentView viewController:self];

并在初始视图中:

//This is called from within previous call initWithContent:ciewController:
- (void)setupGestures
{
    UILongPressGestureRecognizer *rullerGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(rullerTapAction:)];
    [rullerGestureRecognizer setNumberOfTouchesRequired:2];

    //view here is a content view passed into init, basically the same one
    //to which first recognizer is added, however selector action is contained 
    //in this view, and this view is target for this recognizer
    [view addGestureRecognizer:rullerGestureRecognizer];
}

这会不会是个问题??已经试过了

[gesture requireGestureRecognizerToFail:otherGesture];

以及添加识别器的视图的委托方法:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return YES;
}
4

0 回答 0