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

问题描述:

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

I have a UIScrollView where I added a subview. The scrollview scrolls fine vertically and that is all it should do. I would now like to recognize left/right swipes in the subview with the help of a UISwipeGestureRecognizer. I know it is possible, but I have not come across a solution and several tries have been unsuccessful.

试试这些:


  • 设置 UIGestureRecognizer的代表

实施 shouldRecognizeSimultaneouslyWithGestureRecognizer

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


  • 实施 shouldReceiveTouch

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


  • 希望这有助于