开发者

UIResponder chain question

Im not too informed on the nitty gritty of modifying the responder chain, so if this is stupid pls dont bash me ;)

basically i have 2 view stacks(blue) as a subview of a parent view(red)

th开发者_运维百科ey are both occupying the full frame of parent at one point in time, so obviously only the one on top is getting touch events, which travel upstream to the parent view(red) and on to window.

During some cases i want the touch input to be picked up by the eligible child view of 'other' view stack. That is, the view that woud be receiving these inputs if the current topmost view had userinteractionenabled set to no.

Setting userinteractionenabled works but i feel like its a dirty hack. The gist is this topmot view is mostly transparent and i want the events when touched in the specified region to end up on the other stack.

here is a picture to help visually explain, and keep in mind both blue views are 100% of parent.

http://c.crap.ps/35a5


You can override hitTest:withEvent: in each of the views to control who gets to "consume" the touch.

In your example I am assuming that the greenish areas are subviews that you want to consume the touch events. If so, then try this for the hitTest method:

-(UIView*) hitTest:(CGPoint)point withEvent:(UIEvent *)event {  
    UIView *hitView = [super hitTest:point withEvent:event];
    return (hitView == self) ? nil : hitView;
}

This method checks if the touch hits any of the subviews. If it does then it lets that subview consume the touch, otherwise it lets the touch continue through the hierarchy.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜