title: Animate constraint change smoothly with pan gesture
body: <blockquote>
    <p><strong>How to animate constraint change smoothly with pan gesture in iOS?</strong></p>
  </blockquote>
  
  <p>I am trying to develop a screen, where a view is at bottom of the screen. And I've added pan gesture to that view. On dragging that view I want change top constraint of that view. Pan gesture is only allowed in vertical and downward direction. I have added some limit for dragging the view. It working but not smoothly. How to animate constraint change smoothly with pan gesture? Here is my code.</p>
  
  <pre><code> - (void)handleGesture:(UIPanGestureRecognizer *)sender
  {
      CGPoint velocity = [sender velocityInView:_locationContainer];
  
      [sender setTranslation:CGPointMake(0, 0) inView:self.view];
  
      if (fabs(velocity.y) &gt; fabs(velocity.x)) {
  
          NSLog(@"velocity y %f ",velocity.y * 0.13);
  
          if(velocity.y &lt; 0 &amp;&amp; (self.locationDetailsTop.constant &gt; minimumTop) )
          {
              NSLog(@"gesture moving Up");
              self.locationDetailsTop.constant = self.locationDetailsTop.constant - fabs(velocity.y * 0.1);
          }
          else if (self.locationDetailsTop.constant &lt; firstTop)
          {
              NSLog(@"gesture moving Bottom");
  
              self.locationDetailsTop.constant = self.locationDetailsTop.constant + fabs(velocity.y * 0.1);
          }
  
          [self.view layoutIfNeeded];
          [UIView animateWithDuration:0.1 animations:^{
              [self.mapView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.locationContainer.frame.origin.y)];
          }];
      }
  }
  </code></pre>
  
  <p>This is sample image, 
  My screen is of the same kind like this, But on my screen, there is a map view instead of the calender view</p>
  
  <p><a href="https://i.stack.imgur.com/a8Gf6.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/a8Gf6.gif" alt="enter image description here"></a></p>