7

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

Sam
  • 3,659
  • 3
  • 36
  • 49
  • Hmmm, well the code is quite complex, but I coded up the simplest possible example to post up here and it worked OK... so +1 for the nudge in the right direction.............. will post when I've figured out the difference – Sam Mar 22 '10 at 15:48

2 Answers2

8

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

yonel
  • 7,855
  • 2
  • 44
  • 51
1

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];
}
Martin
  • 1,570
  • 3
  • 19
  • 32
  • the subviews don't receive the event either. If I add a subview to the place where the touchesBegan event occurred, neither the subview nor the superview receive touchesMoved/Cancelled/Ended – Sam Mar 22 '10 at 09:41
  • 3
    This passes the touch to the superCLASS, not the superVIEW. ;) – Pascal Mar 25 '10 at 15:57