views:

180

answers:

1

I have a UIControl (or UIView, could have either of them, doesnt matter), and this is covered by another UIControl. The other UIControl reacts nicely on touches. But the underlying UIControl also needs to know about the touch and if the touch was actually "on it" or not (from the user's perspective). The covering UIControl is partially transparent.

How to catch this touch on thta underlying UIControl?

+1  A: 

I think there are couple ways you could go about this...

You could pass the touch event on to the other control...though i don't think that'll work if you're moving the upper view over the other view? You might have to experiment.

The easier way might be just to see if the lower rect contains the touch point:

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent*)event {
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint touchLocation = [touch locationInView:self];
    if (CGRectContainsPoint(lowerView.frame, touchLocation)) {
        <doyourthing>
}

I don't recall offhand but you may need to convert the view coordinates between the two views?!? or you could ask the view itself with - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event

Meltemi