gpt4 book ai didi

objective-c - 在 UIScrollView 中禁用 2 指滚动

转载 作者:太空狗 更新时间:2023-10-30 03:14:23 26 4
gpt4 key购买 nike

我想在我的 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,我可以成功地禁用单指滚动并需要两次触摸。

有什么想法吗?

最佳答案

我意识到这是一个旧线程,但我花了很长时间才弄明白,所以我想我会分享。这是我为禁用双指滚动所做的操作:

// 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];

关于objective-c - 在 UIScrollView 中禁用 2 指滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8210614/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com