我有一个UIScrollView,在其中添加了一个子视图。UIScrollView在垂直方向上可以很好地滚动,并且这就是它应该做的全部内容。现在,我想在子视图中通过UISwipeGestureRecognizer来识别左右滑动操作。我知道这是可能的,但我没有找到解决方案,尝试了几次也不成功。
我有一个UIScrollView,在其中添加了一个子视图。UIScrollView在垂直方向上可以很好地滚动,并且这就是它应该做的全部内容。现在,我想在子视图中通过UISwipeGestureRecognizer来识别左右滑动操作。我知道这是可能的,但我没有找到解决方案,尝试了几次也不成功。
Set the delegate of your UIGestureRecognizer
and
Implement shouldRecognizeSimultaneouslyWithGestureRecognizer
:
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return YES;
}
Implement shouldReceiveTouch
:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return otherGestureRecognizer == scrollView.panGestureRecognizer;
}
-shouldRecognizeSimultaneouslyWithGestureRecognizer::
,但奇怪的是它们没有被调用... - the_critic