UITouch Event Propagation To Background UIViews
Posted
by drewww
on Stack Overflow
See other posts from Stack Overflow
or by drewww
Published on 2010-05-21T23:10:04Z
Indexed on
2010/05/21
23:10 UTC
Read the original article
Hit count: 605
I'm having troubles getting any UIView
that's not the foreground UIView
to receive UITouch
events. I'm building an all-Core Graphics-app, so I'm not using any built in UIViews or IB or anything - everything is programmatically constructed and drawn into.
Here's my view hierarchy:
- Root View
- Type A Container
- Type A View
- Type A View
- Type A View
- Type B Container
- Type B View
- Type B View
- Type B View
The containers are just vanilla UIView
objects that I create programmatically and add instances of Type A and B to when they're created. I did this originally to make hitTest
ing easier—Type A objects can be drag-and-dropped onto Type B objects. Type A objects receive touch events fine, but Type B objects (which are contained by Type B Container
which is behind Type A Container
) don't receive touch events. Both containers occupy the entire screen; they're basically just convenience containers.
If I pull Type B Container
to the front (eg [self.view bringSubviewToFront:Type B Container
]) it receives events properly, but then the Type A Container
doesn't get events.
How do I propagate events from the view that's on top? Both views occupy the entire screen, so it makes sense that the top-most view is catching the events, but how should I get it to pass those events on to Type B Container
? I could inject some code in the container that passes the touch events back to the main ViewController
which can pass them on to Type B Container
but that feels really messy to me. Is there a nicer way to not have the Type A Container
stop propagation? What's the best practice here?
© Stack Overflow or respective owner