Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not receiving touchesEnded/Moved/Cancelled after adding subView

Title more or less says it all. In response to a touchesBegan event, my UIViewController recolours itself and adds some subviews.

It never receives the touchesEnded. I guess because the added subviews are somehow intercepting the event. I tried calling resignFirstResponder on the subviews to no avail.

The code works fine when I don't add the child views and the touch events are called as normal.

Any ideas?

Thanks

EDIT: Bit of detail and how I fixed it.

Basically I had a master view with some subviews, when I touched the subview, the event would be passed through to the master view, however, on this event I was removing the subviews and adding new ones in their place. The fact that the touch originated on a subview which no longer existed meant that the rest of the touch was lost.

I fixed this by overriding hitTest:withEvent in my master view, to stop touches ever getting tested against the subviews

like image 521
Sam Avatar asked Mar 19 '10 17:03

Sam


2 Answers

Did you try to set the userInteractionEnabled property to NO for the subview before adding it as a subview ?

like image 171
yonel Avatar answered Nov 09 '22 17:11

yonel


You're going to need pass the touch from the subview onto the superview using something like this:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    [super touchesBegan:touches withEvent:event];
}
like image 1
Martin Avatar answered Nov 09 '22 18:11

Martin