简体   繁体   中英

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.

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 .

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM