Nazik
Nazik

Reputation: 8444

Long press and pan gesture in UICollectionView

I'm working on a custom calendar downloaded from GitHub. It's a custom view with UICollectionView added in it to show date cells. I'm adding a functionality of dragging over the cells to get multiple date values. For that I've added UILongpressgesture

What I've tried,

@property (nonatomic, strong) UILongPressGestureRecognizer *dragDateGesture;

 self.dragDateGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleDragBeginDate:)];
 self.dragDateGesture.delegate = self;
 self.dragDateGesture.minimumPressDuration = 0.05;
 [self.collectionView addGestureRecognizer:self.dragDateGesture];

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)recognizer
{
return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return YES;
}
- (void)handleDragBeginDate:(UIPanGestureRecognizer *)recognizer
{
 NSLog(@"Gesture recognised");
}

In the above code, I've added long press gesture and setting simultaneous gesture recognizer to yes. I'm not sure, whether adding a long press gesture will call the handleDragBeginDate method with UIPanGestureRecognizer getter. I'm new to gesture concept. It's not calling that method while dragging over collectionview.

What might be the issue here? can anyone please guide me on this?

If the way that I'm proceeding is wrong, new suggestions will be greatly appreciated.

Upvotes: 0

Views: 1047

Answers (2)

Lumialxk
Lumialxk

Reputation: 6379

UICollectionView has its own panGestureRecognizer and pinchGestureRecognizer. So it's no need to add. I suggest you get touch events in its delegate functions. This is one of these:

-(void)scrollViewDidScroll:(UIScrollView *)scrollView;

Upvotes: 1

lawicko
lawicko

Reputation: 7344

As far as I know, the collection view doesn't have an edit mode similar to what the table view has. Fortunately, someone has already solved this problem for you.

Upvotes: 1

Related Questions