Wednesday, 21 August 2013

Gesture recognizer touches on overlapping objects

Gesture recognizer touches on overlapping objects

I've been searching everywhere for an answer to this and although others
have posted some similar questions. I am just getting confused.
I have over 20 buttons on screen, each with an 84x88 image, that are
animating around the place. Thier animation causes them to overlap quite
often, which is what I want.
I've implemented a gesture recognizer on the main view
- (void)addGestureRecognizersToPiece:(UIView *)piece
{
UITapGestureRecognizer *singletapGesture = [[UITapGestureRecognizer
alloc] initWithTarget:self action:@selector(tapPiece:)];
singletapGesture.numberOfTapsRequired = 1;
singletapGesture.cancelsTouchesInView = NO;
[singletapGesture setDelegate:self];
//[piece addGestureRecognizer:singletapGesture];
[self.view addGestureRecognizer:singletapGesture];
//[singletapGesture release];
}
This works great using the presentation layer to hittest even with the
animations on the fly, but the touch gets recognised by the button views
that are under the top most button.
I have tried many ways, including the delegate method,
shouldRecognizeSimultaneouslyWithGestureRecognizer,
canPreventGestureRecognizer and shouldReceiveTouch
I've tried adding the gesture recogniser to every button, but that just
makes the touch recognition unbearable slow and sometimes doesn't register
at all. I can't seem to figure out how to only have the top most view
register the touch.
Should I be using UIviews instead of buttons?
Any help appreciated.

No comments:

Post a Comment