如何使用UIScrollView滚动并拥有手势识别器? [英] How to have a UIScrollView scroll and have a gesture recognizer?

查看:107
本文介绍了如何使用UIScrollView滚动并拥有手势识别器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UIScrollView上有一个手势识别器,但是它很难被调用,因为UIScrollView会吃掉所有手势。

I have a gesture recognizer on a UIScrollView, however it hardly ever gets called as the UIScrollView eats all the gestures.

我用这条线部分解决了这个问题: [scrollView.panGestureRecognizer requireGestureRecognizerToFail:rightSwipe]; 但是,此行导致我的识别器始终被接受(所需行为)并且滚动视图不滚动。

I partially got around this issue with this line: [scrollView.panGestureRecognizer requireGestureRecognizerToFail:rightSwipe]; however, this line results in my recognizer always being accepted (the desired behavior) and the scroll view not scrolling.

也就是说,滚动时,会接受识别器,但视图不会滚动。

That is, when you scroll, the recognizer is accepted but the view doesn't scroll.

如何我可以解决这个问题,还是有替代解决方案?

How can I get around this, or is there an alternate solution?

谢谢!

推荐答案

创建 UIScrollView 的子类。在你的新子类中添加此方法

Make a subclass of UIScrollView. Add this method in your new subclass

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

将scrollView类设为新的scrollview子类。

Make your scrollView class to your new scrollview subclass.

这篇关于如何使用UIScrollView滚动并拥有手势识别器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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