3

我有一个 UIScrollView,我在其中添加了一个子视图。滚动视图可以很好地垂直滚动,这就是它应该做的。我现在想在 UISwipeGestureRecognizer 的帮助下识别子视图中的左/右滑动。我知道这是可能的,但我还没有找到解决方案,而且几次尝试都没有成功。

4

2 回答 2

5

试试这些:

  • 设置你的代表UIGestureRecognizer

  • 实施shouldRecognizeSimultaneouslyWithGestureRecognizer

    -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    return YES;
    }
    
  • 实施shouldReceiveTouch

    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
    {
     return YES;
    }
    

希望这可以帮助

于 2012-12-27T12:46:23.437 回答
0

我能够使用新的 iOS 7 UIGestureRecognizerDelegate 方法完成一些相关的事情(直接在滚动视图上添加两指滑动手势识别器):

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
        shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return otherGestureRecognizer == scrollView.panGestureRecognizer;
}

然而,结果并不完美——等待滑动手势识别器失败的延迟首先导致滚动视图的平移手势识别器延迟,因此当您开始滚动时,正常滚动明显延迟。

于 2014-05-30T22:06:04.707 回答