UIScrollView子视图中的水平UISwipeGestureRecognizer? (UIScrollView只需要识别垂直滚动)

我有一个UIScrollView,我添加了一个子视图。 scrollview垂直滚动,这就是它应该做的。 我现在想通过UISwipeGestureRecognizer来识别子视图中的左/右滑动。 我知道这是可能的,但我没有遇到一个解决scheme,并尝试了几次失败。

试试这些:

  • 设置你的UIGestureRecognizer的委托

  • 实现shouldRecognizeSimultaneouslyWithGestureRecognizer

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

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

希望这可以帮助

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

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

但是,结果并不完美 – 等待滑动手势识别器首先失败的延迟会导致滚动视图的滑动手势识别器发生延迟,因此当您开始滚动时,正常的滚动显着延迟。