开发者

subview outside parentview frame events

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 开发者_Go百科ends at {0, 372} even if B UIview is displayed over UITableView.

Any solution please ?


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 http://img256.imageshack.us/img256/6789/screenshot20091030at350.png

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜