Reputation: 770
I have a UICollectionView
to which I have added UILongPressGestureRecognizer
and UIPangestureRecognizer
for long press and reordering cells. And also I have added UIPanGestureRecognizer
for all the UICollectionViewCells
to show delete and few options on the right side.
My problem is when I pan two UICollectionViewCells
with two fingers, both the UICollectionViewCells
are detecting the pan and showing the options.
I want only one of the UICollectionViewCell
to detect its UIPangestureRecognizer
at a time. Is there any solution?.
Can anyone please help me out on this?. Thanks in advance.
Upvotes: 0
Views: 2382
Reputation: 2470
Have you tried the minimumNumberOfTouches / maximumNumberOfTouches property of UIPangestureRecognizer?
Upvotes: 4
Reputation: 3389
You can disable multi touch on collection it self. by making simple property.
[UICollectionView setMultipleTouchEnabled:NO];
If still problem is not being solve due to Gesture view implementation then you can use TouchedFlag
for maintain touch on cell.
You can set in
- (IBAction) panGesture:(UIPanGestureRecognizer *)gesture;
You can set TouchedFlag
to 1 while
if (gesture.state == UIGestureRecognizerStateBegan)
{
TouchedFlag=1;
}
And set back while PanGesture
get ended in
if (gesture.state == UIGestureRecognizerStateEnded)
{
TouchedFlag=0;
}
So your finale code should look like
- (IBAction) panGesture:(UIPanGestureRecognizer *)gesture
{
if (gesture.state == UIGestureRecognizerStateBegan && TouchedFlag==0)
{
TouchedFlag=1;
//Do your PAN openration
}
else if (gesture.state == UIGestureRecognizerStateBegan && TouchedFlag==1) {
//just prompt msg to user then single view at a time allowd to PAN
}
else if (gesture.state == UIGestureRecognizerStateEnded) {
TouchedFlag=0;
}
}
Upvotes: 3