vendredi 1 juillet 2016

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.

Aucun commentaire:

Enregistrer un commentaire