同时手势iOS无法按预期工作

时间:2017-08-21 11:29:32

标签: ios uigesturerecognizer simultaneous

我正在尝试同时双指左滑动和双指右滑动。

在我的viewDidLoad中,我按如下方式初始化手势:

swipeRecognizerL= [[UISwipeGestureRecognizer alloc]
                       initWithTarget:self action:@selector(handleSwipeL)];
swipeRecognizerL.direction=UISwipeGestureRecognizerDirectionLeft;
swipeRecognizerL.numberOfTouchesRequired=2;
swipeRecognizerL.delegate = self;


swipeRecognizerR= [[UISwipeGestureRecognizer alloc]
                       initWithTarget:self action:@selector(handleSwipeR)];
swipeRecognizerR.direction=UISwipeGestureRecognizerDirectionRight;
swipeRecognizerR.numberOfTouchesRequired=2;
swipeRecognizerR.delegate = self;

然后我将识别器添加到AVPlayerViewController;

AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
[controller.view.subviews[0] addGestureRecognizer:swipeRecognizerR];
[controller.view.subviews[0] addGestureRecognizer:swipeRecognizerL];

委托方法如下所示:

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
    return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{

    NSLog(@"This one:%@,  theOtherOne:%@", gestureRecognizer, otherGestureRecognizer);
    return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    return YES;
}

现在,单个双指滑动被识别为OK,但是当我进行双指双指滑动(一个左手,一个右手)时,不知何故,它似​​乎被解释为捏手势,根据登录< em> shouldRecognizeSimultaneouslyWithGestureRecognizer :

  

这一个:; target =&lt;(action = handleSwipeR,   目标=)取代; numberOfTouchesRequired = 2;   direction = right&gt ;,OtherOne:;目标=   &lt;(action = _handlePinchGesture:,target =)&gt;&gt;

任何线索我做错了什么?如果您需要其他信息,请与我们联系。

0 个答案:

没有答案