我正在重写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];
}