制作平移手势需要所有4个滑动手势失败

时间:2014-11-18 09:40:47

标签: ios objective-c iphone uipangesturerecognizer uiswipegesturerecognizer

我为我的视图注册了所有4个滑动手势向上,向下,向左和向右滑动)。我还想对同一个视图使用 Pan手势,但requireGestureRecognizerToFail允许我只指定其中一个 Swipe手势

有没有办法做这样的事情:

[panGesture requireGestureRecognizersToFail: @[swipeUp, swipeDown, swipeLeft, swipeRight]];

谢谢。

2 个答案:

答案 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];