I have a UIView subclass with several subviews and I want to handle these events in the class:
-
开发者_运维问答
- touchesBegan:withEvent:
- touchesMoved:withEvent:
- touchesEnded:withEvent:
but I also want these event to be called at the subviews. How can I accomplish that?
(I have already tried with hitTest, but I only get the touchesBegan event and no touches are send with the method)
I have managed to solve it by overriding the following method at the main window:
- (void)sendEvent:(UIEvent*)anEvent
I also check if it is the right event with through
if ([[[anEvent allTouches] anyObject] phase] == UITouchPhaseBegan)
I do the same for UITouchPhaseMoved
and UITouchPhaseEnded
, execute my custom code and then send [super sendEvent:anEvent];
精彩评论