I'm adding programmatically an UIView B to another UIView A.

The A frame is {{0, 372}, {320, 44}}. B UIView is add at {0, -74} and is {320, 74} wide.

My problem is that B touch events are not handled.

More precisely touch events are handled to a sibling UITableView of UIView A wich ends at {0, 372} even if B UIview is displayed over UITableView.

Any solution please ?

No correct solution


To determine the view in which a touch event falls, Cocoa traverses the view hierarchy (and sends each subview a hitTest:withEvent: message. In turn, this message calls pointInside:withEvent: on itself, which returns a boolean value that indicates whether the view contains the specified point.

Presumably, you could subclass your UIView A and override its pointInside:withEvent: method to return YES also for points that are outside A's bounds but inside B's.

Okay, your B-UIView is completely outside and above the bounds of A-UIView. If you set up two generic views with the same frames like this in Interface builder and set the backgrounds to different colors, you will see absolutely nothing of B-UIView. alt text

It's exactly like defining a view whose frame is outside the bounds of the screen. If no part of it is visible it will not trap touches because it's off in undefined space having tea with the square root of negative one.

The UITableView is handling the hits because the B UIView is not in the responder chain at all.

You need to make B-UIView a sibling of A-View instead of an invisible and inactive subview. Then overlay that on the bottom of the UITableView.

You cannot do this in such way. You should add both your A and B views to another view C. And it will work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top