在手势识别器被取消后以编程方式启动hitTest:WithEvent,并返回不同的UIView以响应事件



我正在重写hitTest:withEvent以返回self(最底部的视图)-

当返回self时,我的视图将响应触摸事件,进而启动手势识别器。

如果一个手势被取消或发生了某种情况,我想手动启动hitTest:withEvent,然后返回不同的视图来处理发生的相同事件/触摸序列。这是必要的,因为手势识别器仅在hitTest:withEvent返回手势视图并且其状态变为began之后才启动。

我不知道如何做到这一点-我想过手动调用我的子视图

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
}

但我没有事件参数(手势收到)

我认为这是不可能的,将触摸事件传递给UIGestureRecognizer是私有的API。但您可以将触摸事件(接收到的最底部视图)传递给任何您喜欢的视图,并进行自己的手势识别。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UIView* selectView = [self _findMatchView];
// maybe convert touches to selectView coordinate
[selectView handleTouchBegan:touches withEvent:event];
}

最新更新