我为我的视图注册了所有4个滑动手势(向上,向下,向左和向右滑动)。我还想对同一个视图使用 Pan手势,但requireGestureRecognizerToFail
允许我只指定其中一个 Swipe手势。
有没有办法做这样的事情:
[panGesture requireGestureRecognizersToFail: @[swipeUp, swipeDown, swipeLeft, swipeRight]];
谢谢。
答案 0 :(得分:1)
首先,简要介绍一下这个link
如果我说得对,你想要平移手势,所以:
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:myView
action:@selector(handlePan:)];
[myView addGestureRecognizer: panGesture];
然后,在handlePan:
你应该:
- (void) handlePan:(UIPanGestureRecognizer *)panGestureRecognizer
{
CGPoint translation = [uiPanGestureRecognizer translationInView:self.superview];
myView.center = CGPointMake(lastLocation.x + translation.x,
lastLocation.y + translation.y);
}
答案 1 :(得分:0)
您可以多次调用它:
[panGesture requireGestureRecognizerToFail:swipeUp];
[panGesture requireGestureRecognizerToFail:swipeDown];
[panGesture requireGestureRecognizerToFail:swipeLeft];
[panGesture requireGestureRecognizerToFail:swipeRight];