It's an interesting problem you have that is probably something best addressed through a rethink of the way you have things structured. But to make it work the way you suggest you need to catch the touch event in the current top view, pass it to the parent and then propagate it down through all subviews of the parent view. To make this work you would need the touchesBegan: (or whatever other method you use to intercept the touch) to do nothing in all the views, doing the action only in the method called by the parent view.
It's an interesting problem you have that is probably something best addressed through a rethink of the way you have things structured. But to make it work the way you suggest you need to catch the touch event in the current top view, pass it to the parent and then propagate it down through all subviews of the parent view. To make this work you would need the touchesBegan: (or whatever other method you use to intercept the touch) to do nothing in all the views, doing the action only in the method called by the parent view.
Which is really another way of saying don't handle touches in the views, catch them but notify the parent view view and then call subview methods as required to cause the effect you want. - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { // Do nothing, parent view calls my parentNotifiedTouchesBegan method self. Superview touchesBegan:touches withEvent:event; } - (void) parentNotifiedTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { // Act on the touch here just as my sibling views are doing } Note I changed super to self.
Superview in that code. You may or may not also want to call super's method depending on what you are doing, and the place to call that may be in parentNotifiedTouchesBegan. You can know which subView sent the event of course, just use a custom method to notify the superview instead of calling its touchesBegan:.
Use a self argument.
Thanks Adam! Would this solution be compatible with gesture recognizers? At first glance it looks like I will have to reimplement the wheel if I go this route.
– hgpc yesterday And I would very much like to re-structure things, but I don't see how in my case. TopChild has transparency, both topChild and bottomChild can "move" (thus topChild cannot be a subview of bottomChild), and both need to respond to touches. – hgpc yesterday It should be possible, you would just be passing the gestureRecognizer object received by the callback up to the parent rather than a simple touch.At least in the project I have handy this would work for UIPinchGestureRecognizer.
– Adam Eberbach yesterday Now I'm thinking you don't need to catch events in subviews at all, in fact you can disable interaction so that the base view gets everything. No need to do the notification step. Just have base view catch and interpret everything and cause the views to act.
You should be able to isolate the views that should get the event by comparing the point (- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view) to the subview's frames (CGRectContainsPoint). – Adam Eberbach yesterday That was what I was trying now! That said, I find it very strange that this has to be done "manually".
I would imagine this is a pretty common problem. – hgpc yesterday.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.