3

我想在检测到第二次触摸后停止滚动并用我自己的捏合手势处理触摸。我在滚动视图中试过这个:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if(event.allTouches.count > 2)self.panGestureRecognizer.enabled = NO;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    if(event.allTouches.count > 2)self.panGestureRecognizer.enabled = YES;
}

但它不起作用。

试试这个:

scroll.panGestureRecognizer.maximumNumberOfTouches = 1;

但什么都没有

4

4 回答 4

1

我找到解决方案。我重新定义了 UIScrollView,并添加:

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

并禁用\启用平移手势:

if(pinch.state == UIGestureRecognizerStateBegan) scroll.panGestureRecognizer.enabled = NO; 
if(pinch.state == UIGestureRecognizerStateEnded) scroll.panGestureRecognizer.enabled = YES; 

现在我的捏手势起作用了。

于 2012-12-21T11:08:18.020 回答
0

您可以使用这样的禁用滚动视图:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

       if ([touches count] == 2) {

       //Disable scrollview 
    }
 }
于 2012-12-21T10:44:43.337 回答
0

delayContentTouches属性设置UIScrollView为 NO(而不是默认的 YES)。这将允许触摸立即传播到subviews滚动视图。

于 2012-12-21T11:20:16.363 回答
0

我发现设置 UIPangestureRecognizer 的 enabled 属性不起作用,至少在我的代码中是这样。但是,设置 UIScrollView 的 scrollEnabled 属性对我有用。

scrollView.scrollEnabled = false;
scrollView.scrollEnabled = true;
于 2016-07-23T01:31:10.023 回答