Passing touch events on to subviews

Posted by Egil Jansson on Stack Overflow See other posts from Stack Overflow or by Egil Jansson
Published on 2010-04-06T19:55:25Z Indexed on 2010/04/06 21:33 UTC
Read the original article Hit count: 682

I have a view within a UIScrollView that loads an additional subview when the user presses a certain area. When this additional subview is visible, I want all touch events to be handled by this - and not by the scrollview.

It seems like the first couple events are being handled by the subview, but then touchesCancelled is called and the scrollview takes over the touch detection.

How can I make sure that the subview gets all the events as long as the movement activity is being performed on this view?

This is my implementation on touchesMoved - which I thought would do the job...

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [[touches allObjects] objectAtIndex:0];
    CGPoint touchPt = [touch locationInView:self];

    UIView *hitView = [self hitTest:touchPt withEvent:event];
    UIView *mySubView = subviewCtrl.view;

    if(hitView == mySubView) {
        [subviewCtrl.view touchesMoved:touches withEvent:event];
    }
    else {
        NSLog(@"Outside of view...");
    }
}

© Stack Overflow or respective owner

Related posts about iphone-sdk-3.0

Related posts about iphone