Limit touches recognized on UIScrollView

心不动则不痛 提交于 2019-12-11 20:23:38

问题


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:


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.



来源:https://stackoverflow.com/questions/13013264/limit-touches-recognized-on-uiscrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!