title: 2 Finger Pan in ScrollView w/ Other Gestures - iOS SDK
body: <p>I have a main UIView, which contains a scrollview. I have set up UIGestureRecognizer for the main view for 4 types of swipes using this code:</p>
  
  <pre><code>UISwipeGestureRecognizer *swipeUpRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(upCommand)];
  [swipeUpRecognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
  [mainGameView addGestureRecognizer:swipeUpRecognizer];
  ... // Done 4 times for each direction
  </code></pre>
  
  <p>When I disable scrolling on the scrollview, this code works great (I can swipe anywhere on the screen and the associated actions perform as expected). However, I want to add functionality so that if I touch two fingers on the scrollview, I can pan back and forth as a scrollview usually functions. I tried adding a gesture recognizer to the scrollview to detect when two fingers pan:</p>
  
  <pre><code>- (void)viewDidLoad
  {
      UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(recognizePan)];
      panGestureRecognizer.minimumNumberOfTouches = 2;
      panGestureRecognizer.maximumNumberOfTouches = 2;
      [scrollView addGestureRecognizer:panGestureRecognizer];
  }
  
  - (void)recognizePan
  {
      [gameScrollView setScrollEnabled:YES];
  }
  </code></pre>
  
  <p>I used this in conjunction with the following method to disable scrolling again once the fingers are lifted:</p>
  
  <pre><code>- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
  {
      [gameScrollView setScrollEnabled:NO];
  }
  </code></pre>
  
  <p>This kind of worked, but not in the way I want it to. When I drag two fingers on the scrollview, scrolling would be set to enabled, but I can't use those two fingers to scroll. I first need to lift the two fingers and then I am able to scroll with one finger (two fingers don't work). And when I lift up the single finger that could scroll through the scrollview, scrolling is disabled, as set in <code>scrollViewDidEndDragging</code>.</p>
  
  <p>Obviously, this type of scrolling would not be very user-friendly, but I can't seem to find a way to set the scrollview so it only scrolls when two fingers are dragging on the scrollview. Thanks for any help in advance.</p>
  
  <p>~ 17-year-old amateur iOS developer &amp; new to gestures</p>
  
  <p>EDIT: As per one of the suggestions from <a href="https://stackoverflow.com/questions/787212/scrolling-with-two-fingers-with-a-uiscrollview">this question</a>, I have tried implementing a subclass of UISubView to override the default touchesBegan method, but I haven't been able to get it to work.</p>
  
  <p>CustomScrollView.h:</p>
  
  <pre><code>@interface CustomScrollView : UIScrollView 
  {
  }
  
  @end
  </code></pre>
  
  <p>CustomScrollView.m:</p>
  
  <pre><code>#import "CustomScrollView.h"
  
  @implementation CustomScrollView
  
  - (id)initWithFrame:(CGRect)frame 
  {
    return [super initWithFrame:frame];
  }
  
  - (void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event 
  {   
    // What goes here so that The action it can be called from the ViewController.h
  }
  
  @end
  </code></pre>
  
  <p>ViewController.h:</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  @class CustomScrollView;
  
  @interface ViewController : UIViewController &lt;UIScrollViewDelegate&gt;
  {
    CustomScrollView *scrollView;
  }
  
  @end
  </code></pre>
  
  <p>ViewController.m:</p>
  
  <pre><code>- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event 
  {
    // What goes here?
  }
  </code></pre>