views:

356

answers:

3

Hi, 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 ?

A: 

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

Morion
A: 

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.

Ole Begemann
I have the same problem as lefakir, and would prefer not to create a third view with which to contain the other two. The above solution also popped into my head; does the downvote mean the solution isn't kosher? And if not, why not?
Will Baker
A: 
TechZen