I have all 4 Swipe gestures registered for my view ( Swipe up, down, left and right ). I would also like to use the Pan gesture for the same view, but requireGestureRecognizerToFail
allows me to specify only one of the Swipe gestures .
Is there a way to do something like this:
[panGesture requireGestureRecognizersToFail: @[swipeUp, swipeDown, swipeLeft, swipeRight]];
Thank you.
First, Take a brief look at this link
If I get u right, u want pan gesture, so:
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:myView
action:@selector(handlePan:)];
[myView addGestureRecognizer: panGesture];
Then, in handlePan:
u should:
- (void) handlePan:(UIPanGestureRecognizer *)panGestureRecognizer
{
CGPoint translation = [uiPanGestureRecognizer translationInView:self.superview];
myView.center = CGPointMake(lastLocation.x + translation.x,
lastLocation.y + translation.y);
}
You can just call it multiple times like so:
[panGesture requireGestureRecognizerToFail:swipeUp];
[panGesture requireGestureRecognizerToFail:swipeDown];
[panGesture requireGestureRecognizerToFail:swipeLeft];
[panGesture requireGestureRecognizerToFail:swipeRight];
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.