The method -(NSUInteger)numberOfTouches
of UIGestureRecognizer
can tell you how many touches are placed on your view. Also this Event Handling Guide will may help you :)
Another way to go would be UITapGestureRecognizer
, which can be configured with numberOfTouchesRequired
to limit one recognizer to a special amount of fingers.
EDIT
I suggest you to use a private BOOL which locks interaction with one of the gesture recognizers, if another one is active.
With the new LLVM Compiler available in XCode 4 and later, you can declare @private variables in default categories inside your implementation (.m) file:
@interface YourClassName() {
@private:
BOOL interactionLockedByPanRecognizer;
BOOL interactionLockedByGestureRecognizer;
}
@end
@implementation YourClassName
... your code ...
@end
Your method handling the pan interaction (I assume you'll do some kind of animation at the end to move around stuff):
- (void)handlePan:(id)sender
{
if (interactionLockedByGestureRecognizer) return;
interactionLockedByPanRecognizer = YES;
... your code ...
[UIView animateWithDuration:0.35 delay:0.0 options:UIViewAnimationCurveEaseOut
animations:^{
[[sender view] setCenter:CGPointMake(finalX, finalY)];
}
completion:^( BOOL finished ) {
interactionLockedByPanRecognizer = NO;
}
];
}
Now you just need to check inside your touchesBegan
, touchesMoved
and touchesEnded
if interactions are locked by the UIPanGestureRecognizer:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if (interactionLockedByPanRecognizer) return;
interactionLockedByGestureRecognizer = YES;
... your code ...
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if (interactionLockedByPanRecognizer) return;
... your code ...
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if (interactionLockedByPanRecognizer) return;
... your code ...
interactionLockedByGestureRecognizer = NO;
}