Sk0prion Sk0prion - 1 year ago 111
Objective-C Question

Disable pan in UIScrollView on pinch by 2 fingers

I want to stop scrolling after detect second touch and handle touches with my own pinch gesture.
I've tryed this in scroll view:

- (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;

But it's doesnt works.

Try this:

scroll.panGestureRecognizer.maximumNumberOfTouches = 1;

But nothing

Answer Source

I find solution. I redefined UIScrollView, and add:

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

And disable\enable pan gesture:

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

Now my pinch gesture works.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download