Iphone – UITouch nil in touchesMoved with light tap-slide

cocoa-touchevent handlingeventsiphone

I have a view object that I can tap and get a valid touch in touchesMoved:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];

If I lightly tap while sliding the object, touchesBegan fires and I call touchesMoved, as before, but this time touch in touchesMoved is nil. Any ideas why that happens? Seems as though the light touch-slide vs. tap causes touchesMoved [[event allTouches] anyObject] to be nil for some reason.

Edit:

Here's a little more info on this setup. When the touchesBegan occurs, it is on viewB, which immediately removes itself from the superview. Now viewA is displaying. This is where the touchesMoved continues. But because it started in viewB, touchesMoved for viewA doesn't do anything and hence the nil. How can I continue the move that started in viewB down into viewA?

Best Answer

Is there any reason you're not using the touches object instead of [event allTouches]?

Related Topic