在UIScrollView中用2个手指捏住pan

时间:2012-12-21 10:40:20

标签: objective-c uiscrollview uigesturerecognizer

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

- (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 个答案:

答案 0 :(得分:1)

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

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

并禁用\ enable pan gesture:

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

现在我的捏动手势有效。

答案 1 :(得分:0)

您可以使用以下方式禁用滚动视图:

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

       if ([touches count] == 2) {

       //Disable scrollview 
    }
 }

答案 2 :(得分:0)

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

答案 3 :(得分:0)

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

names