Limit touches recognized on UIScrollView

2019-09-03 21:00发布

I'm trying to limit the number of touches recognised on a UIScrollView as it's executing with another gesture that has more than one touch required. I don't want the pan & swipe gestures to fire if the number of touches is greater than 1. But I'm having no success.

I've subclassed the UIScrollView and overridden the obvious methods, but numberOfTouches always returns 1?

-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    if (gestureRecognizer.numberOfTouches > 1) 
    {
        return NO;
    }   
    return YES;
}

1条回答
The star\"
2楼-- · 2019-09-03 21:45

Perhaps you can do the following?

for(UIGestureRecognizer* gr in _scrollview.gestureRecognizers)
{
    if([gr respondsToSelector:@selector(setMaximumNumberOfTouches:)])
    {
        gr.maximumNumberOfTouches = 1;
    }
}

No need for sub-classing the scroll view, you can just do this in viewDidLoad of your view controller.

查看更多
登录 后发表回答