Propagation of touch events through subordinate imitations?

I have a stack of subtitles that have user interactive sections (children) and the whole full-screen mode. The problem is that if I touch the non-interactive section at the top of the stack, it will not extend that touch to the rest of the stack. My setup:

view A --view B (full-screen container, not interactive itself, but with interactive subtitles) ---- view B1 (interactive) ---- view B2 (interactive) --view C (same as B) - --- view C1 (interactive) ---- view C2 (interactive)

B and C are full-screen, but B1 / B2 / C1 / C2 are only small sections of the screen.

[a addSubview:b]; [a addSubview:c]; 

If I touch anything outside of C1 / C2, I would like the touch event to check if it got somewhere inside B (B1 / B2), but instead it goes back to A and then to the parent. do it? If I set userInteractionEnabled NO to C, but YES to C1 / C2, it will not receive any calls to internal either, although in this case B will receive the strokes as expected.

edit: manually moving the viewing stack to finish checking only certain sub-items, and not all of them:

 - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { if (self != self.topCustomViewsContainer) { for (UIView *v in self.createdSubviews) { CGPoint newPoint = point; newPoint.x -= v.frame.origin.x; newPoint.y -= v.frame.origin.y; UIView *hit = [v hitTest:newPoint withEvent:event]; if (hit) return hit; } return nil; } return [super hitTest:point withEvent:event]; } 
+4
source share
2 answers

One possibility is to overwrite

 - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event 

in view B. You can return it only if routine B gets into it. Try this as follows:

 - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { UIView *hitView = [super hitTest:point withEvent:event]; if (hitView == self) { return nil; } else { return hitView; } } 
+8
source

Events extend the view hierarchy from child to parent (as you discovered). Two possibilities are possible for me:

Make C child B. Both of them are the same size, and C obviously already has a transparent background, so add it to B and use [viewB bringSubviewToFront:viewC] so that it gets strokes first. Everything that he does not capture will go on to the views below him, then to parent A.

Or: manually capture the strokes and make them view B (sibling C). This includes implementing this in a class controller class

 - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [viewC touchesBegan:touches withEvent:event]; // Note this could be in sibling B or in parent A, depending on which // has a reference to the 'viewC' object } 
0
source

All Articles