问题描述
我在 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 滚动并拥有手势识别器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!