I have a view with two subviews:
- A UIImageView
- A small Custom View which is like a clock with hands that can be rotated.
I have written the code for rotation of hands in touchesBegan and touchesMoved of the custom clock-like view.
This custom view is placed over the image and I have added two-finger zoom,rotation,panGesture to the imageView.
Now My problem is whenever I one of my two finger touches hands of this clock-view, they move and rotate which I dont want.
I want to restrict their touches only when I am doing a single finger gesture on them and not two finger gesture on the image behind it.
EDIT: Here is my code to add the gesture
UIPanGestureRecognizer *panGesture = [[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)] autorelease];
panGesture.maximumNumberOfTouches = 2;
panGesture.minimumNumberOfTouches = 2;
[self.imageView addGestureRecognizer:panGesture];
The method
-(NSUInteger)numberOfTouchesofUIGestureRecognizercan 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 withnumberOfTouchesRequiredto 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:
Your method handling the pan interaction (I assume you’ll do some kind of animation at the end to move around stuff):
Now you just need to check inside your
touchesBegan,touchesMovedandtouchesEndedif interactions are locked by the UIPanGestureRecognizer: