在 UIScrollView 中禁用 2 根手指滚动
我想在 UIScrollView
中禁用两指滚动。
我对其进行了子类化,并使用以下代码调整了其内置手势识别器:
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
,我可以成功禁用单指滚动并需要两次触摸。
有什么想法吗?
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;
}
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.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我意识到这是一个旧线程,但我花了很长时间才弄清楚,所以我想我会分享。这是我禁用两指滚动的方法:
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:
如果您使用iOS SDK 5.0以上,也许您可以直接使用ui pan手势识别器。
if you are using iOS SDK over 5.0, maybe you can use ui pan gesture recognizer directly.
我可以确认这在 iOS 8 中仍然是一个问题,但前提是 UIPanGestureRecognizer 位于 UIScrollView 的底层。使用新的 UIPanGestureRecognizer 创建 UIView 并设置其 MaximumNumberOfTouches 属性按预期工作。
提交了 rdar://20890684 并复制到 http://openradar.appspot.com/radar?id= 6191825677189120。请随意欺骗。
I can confirm this is still an issue in iOS 8, but only when the UIPanGestureRecognizer is underlying a UIScrollView. Creating a UIView with a fresh UIPanGestureRecognizer and setting its maximumNumberOfTouches property works as expected.
Submitted rdar://20890684 and copied to http://openradar.appspot.com/radar?id=6191825677189120. Please feel free to dupe.
问题:
当
UIPanGestureRecognizer
位于UIScrollView
底层时> (不幸的是,这也会影响UIPageViewController
)maximumNumberOfTouches
的行为不符合预期 -minimumNumberOfTouches
但是始终正确限制下端。当监视这些参数时,它们似乎完成了它们的工作 - 只是
UIScrollView
不尊重它们并忽略它们的值!补救措施:
您可以在我的回答中找到解决方案:
UIScrollView 仅用一根手指滚动
PROBLEM:
When the
UIPanGestureRecognizer
is underlying aUIScrollView
(which unfortunately does also effectUIPageViewController
) themaximumNumberOfTouches
is not behaving as expected - theminimumNumberOfTouches
however always limits the lower end correctly.When monitoring these parameters they seem to do their job - it's just that
UIScrollView
doesn't honor them and ignores their values!REMEDY:
You can find the solution in my answer to:
UIScrollView scrolling only with one finger