限制在 UIScrollView 上识别的触摸 [英] Limit touches recognized on UIScrollView

查看:20
本文介绍了限制在 UIScrollView 上识别的触摸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试限制 UIScrollView 上识别的触摸次数,因为它正在执行另一个需要多次触摸的手势.我不想要锅&如果触摸次数大于 1,则滑动手势以触发.但我没有成功.

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.

我已经继承了 UIScrollView 并覆盖了明显的方法,但 numberOfTouches 总是返回 1?

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;
}

推荐答案

也许你可以做到以下几点?

Perhaps you can do the following?

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

无需对滚动视图进行子类化,您只需在视图控制器的 viewDidLoad 中执行此操作即可.

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

这篇关于限制在 UIScrollView 上识别的触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆