Reputation: 2906
I have a overridden UIGestureRecogniser
designed to detect 2 touches, but not necessarily one immediately after the other.
I have:
- (BOOL)canBePreventedByGestureRecognizer:(UIGestureRecognizer *)preventingGestureRecognizer
{
if ([preventingGestureRecognizer isKindOfClass:[UIRotationGestureRecognizer class]])
{
self.state = UIGestureRecognizerStateCancelled;
return YES;
}
if ([preventingGestureRecognizer isKindOfClass:[UISwipeGestureRecognizer class]])
{
self.state = UIGestureRecognizerStateCancelled;
return YES;
}
//Will prevent a conflict with a 2 finger touch only.
if ([preventingGestureRecognizer isKindOfClass:[UITapGestureRecognizer class]])
{
if (preventingGestureRecognizer.numberOfTouches == 2)
{
self.state = UIGestureRecognizerStateCancelled;
return YES;
}
return NO;
}
self.state = UIGestureRecognizerStateRecognized;
return NO;
}
In my MVC I also have a Rotation Gesture Recogniser. My problem is they are conflicting. my doubleTap gesture recogniser is calling its action @selector
when It should be prevented by the above method.
It looks like the above method is not called. I think this is because when the two fingers touch to perform the rotation the following code:
- (void)secondTouchRecived
{
self.state = UIGestureRecognizerStateRecognized;
}
calls the UIGestureResponders
action method and by-passes the prevention method. Ive tried changing it to UIGestureRecogniserStateBegan
but this too seems to by-passes the prevention method.
Upvotes: 2
Views: 474
Reputation: 516
What about specifying a dependency by passing the rotation, swipe and tap gesture recognizers into requireGestureRecognizerToFail: on your custom gesture recognizer? That would prevent your gesture recognizer from transitioning to the Recognized state before the Rotation recognizer gets a chance to process the touches.
Upvotes: 1