(1), 事件分发:如何确定当前点击的点由哪个view来处理?
hit-test来确定hit-view
(2), 事件响应:确定hit-view之后,如何处理事件?
当确定了hit-view之后,第一响应者就是当前的hit-view,然后就会根据响应者链来处理触摸事件。
有手势的先处理手势,手势识别失败后,执行touch系列回调处理。
- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent*)event {
///获取最佳响应的view,可以在这个过程中将一些手势关闭,这样就可以调用当前view的touchesBegan方法了
if(event.type==UIEventTypeTouches) {
// NSSet *touches = [event touchesForView:self];
// UITouch *touch = [touches anyObject];
// if (touch.phase == UITouchPhaseBegan) {
// [self touchesBegan:touches withEvent:event];
// NSLog(@"Touches began");
// }else if(touch.phase == UITouchPhaseEnded){
// NSLog(@"Touches Ended");
// [self touchesEnded:touches withEvent:event];
//
// }else if(touch.phase == UITouchPhaseCancelled){
// [self touchesCancelled:touches withEvent:event];
// NSLog(@"Touches Cancelled");
//
// }else if (touch.phase == UITouchPhaseMoved){
// NSLog(@"Touches Moved");
// [self touchesMoved:touches withEvent:event];
//
// }
}
return[superhitTest:pointwithEvent:event];
}
touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event 这个方法的优先级是比手势优先级低的,有手势先走手势,没有手势才会调用touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event