Direction limitation of UIPanGestureRecognizer
UIPanGestureRecognizer
The simple usage is in other post UIView Gesture
Why should we add limit?
UISwipeGestureRecognizer has direction limitation.
But this recognizer doesn’t have tracking feature of target UIView.
It means that UISwipeGestureRecognizer cannot detect UIGestureRecognizerStateBegin and UIGesture
while swiping.
Situation
We face the problem.
We want to use swipe left,right and UICollectionView at the same UI. Also need drag and drop feature in collection cell.
Direction of UICollectionView swipe is up and down. To use both, we have to prevent up and down in UIPanGestureRecognizer.
Implement UIGestureRecognizerDelegate
Implements following delegation method in managed class not cell
- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer { return YES; }
Set implementation class to GestureRecognizer
UIView *view = [UIView alloc] init]; UIPanGestureRecognizer *recognizer = [UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)]; recognizer.delegate = self; [view addGestureRecognizer:recognizer];
Actually, UITableViewCell has this delegation