在 UIScrollView 中禁用 2 指滚动 [英] Disable 2 finger scrolling in UIScrollView
问题描述
我想在我的 UIScrollView
中禁用两指滚动.
我将其子类化并使用以下代码调整其内置手势识别器:
I'd like to disable two-finger scrolling in my UIScrollView
.
I subclassed it and tweaked its built-in gesture recognizers with the following code:
for (UIGestureRecognizer *mgestureRecognizer in scroller.gestureRecognizers) {
if ([mgestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]])
{
UIPanGestureRecognizer *mpanGR = (UIPanGestureRecognizer *) mgestureRecognizer;
mpanGR.minimumNumberOfTouches = 1;
mpanGR.maximumNumberOfTouches = 1;
}
if ([mgestureRecognizer isKindOfClass:[UISwipeGestureRecognizer class]])
{
UISwipeGestureRecognizer *mswipeGR = (UISwipeGestureRecognizer *) mgestureRecognizer;
mswipeGR.numberOfTouchesRequired = 1;
}
出于某种原因,maximumNumberOfTouches
似乎不起作用.我仍然可以用一根或两根手指滚动.如果我将两个属性都更改为 2
,我可以成功禁用单指滚动并需要两次触摸.
For some reason, maximumNumberOfTouches
does not seem to work. I can still scroll with one or two fingers. If I change both properties to 2
, I can successfully disable one-finger scrolling and require two touches.
有什么想法吗?
推荐答案
我意识到这是一个旧线程,但我花了很长时间才弄明白,所以我想我会分享.这是我为禁用两指滚动所做的操作:
I realize this is an old thread, but it took me a long time to figure this out, so I thought I would share. Here's what I did to disable two-finger scrolling:
// set up a two-finger pan recognizer as a dummy to steal two-finger scrolls from the scroll view
// we initialize without a target or action because we don't want the two-finger pan to be handled
UIPanGestureRecognizer *twoFingerPan = [[UIPanGestureRecognizer alloc] init];
twoFingerPan.minimumNumberOfTouches = 2;
twoFingerPan.maximumNumberOfTouches = 2;
[scrollView addGestureRecognizer:twoFingerPan];
这篇关于在 UIScrollView 中禁用 2 指滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!