title: iOS: Gesture recogniser for smooth scrolling and flicking a View
body: <p>I am building an iPad app where I needed to allow resizing views functionality using divider view provided between two views. The divider view is just a 20px height view between two half screen content views - please refer attached images. </p>
  
  <p>When user scrolls this divider view up or down, both content views changes their sizes appropriately. I have extended <code>UIView</code> and implemented this using <code>touchMoved</code> delegate as code given below in <code>touchesMoved</code> delegate. It works fine. The only thing is missing with <code>TouchMoved</code> is you can't flick divider view to top or bottom directly. You have to drag all the way to top or bottom! </p>
  
  <p>To support flicking the view I have tried <code>UIPanGestureRecognizer</code> but I don't see smooth dragging with it. Setting split-position of parent resizes both content views as shown in the code. When I handle split position change in <code>UIGestureRecognizerStateChanged</code> state, just touching divider view flick it to top or bottom. Handling split position change in <code>UIGestureRecognizerStateEnded</code> does the same but I don't see content view resizing with dividerview scrolling! </p>
  
  <p>Could someone please tell me how could I achieve both smooth scrolling of divider view with resizing content views (like <code>touchMoved</code>) and flicking the view? Any alternative approach would also be fine. Thanks.</p>
  
  <pre><code>- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
      UITouch *touch = [touches anyObject];
      if (touch) {
          CGPoint lastPt = [touch previousLocationInView:self];
          CGPoint pt = [touch locationInView:self];
          float offset = pt.y - lastPt.y;
          self.parentViewController.splitPosition = self.parentViewController.splitPosition + offset;
      }
  }
  
  - (void)handlePan:(UIPanGestureRecognizer*)recognizer {
  
      CGPoint translation = [recognizer translationInView:recognizer.view];
      CGPoint velocity = [recognizer velocityInView:recognizer.view];
  
      if (recognizer.state == UIGestureRecognizerStateBegan) {
      } else if (recognizer.state == UIGestureRecognizerStateChanged) {
         // If I change split position here, I don't see smooth scrolling dividerview...it directly jumps to the top or bottom!
         self.parentViewController.splitPosition = self.parentViewController.splitPosition + translation.y;
      } else if (recognizer.state == UIGestureRecognizerStateEnded) {
        // If I change split position here, the same thing happens at end and I don't see my divider view moving with my scrolling and resizing my views.
          self.parentViewController.splitPosition = self.parentViewController.splitPosition + translation.y;
      }
  }
  </code></pre>
  
  <blockquote>
    <p>Initial screen</p>
  </blockquote>
  
  <p><img src="https://i.stack.imgur.com/5Fm9w.png" alt="Initial screen"></p>
  
  <blockquote>
    <p>Increased top view size by scrolling divider view towards bottom.</p>
  </blockquote>
  
  <p><img src="https://i.stack.imgur.com/e2Hm8.png" alt="Increased top view size by scrolling divider view"></p>
  
  <blockquote>
    <p>Top view is totally hidden here but I have to scroll divider view all
    the way to top. I want to flick the divider view so that it directly
    goes from any position to top</p>
  </blockquote>
  
  <p><img src="https://i.stack.imgur.com/jTY6G.png" alt="Top view is totally hidden here but I have to scroll divider view all the way to top. I want to flick the divider view so that it directly goes from any position to top."></p>