title: UIPanGestureRecognizer - Best way to stop an object moving past a boundary
body: <p>I've got a view within a navigation controller.</p>
  
  <p>I am then adding a subview to this view and offsetting its origin height so that it covers only half the screen (with the other half overflowing off out the bottom of the screen). I want to be able to then drag this view upwards but it get stopped when it hits the bottom of the navigation bar and similarly get stopped when dragged back down when it hits the origin offset point.</p>
  
  <p>I'm using a <code>UIPanGestureRecognizer</code> to handle the dragging of the view and am currently able to somewhat achieve my desired effect using the following code:</p>
  
  <pre><code>func handlePanGesture(recognizer: UIPanGestureRecognizer) {
  
      let minX: CGFloat = recognizer.view!.frame.size.width/2
      let maxX: CGFloat = minX
      let minY: CGFloat = bottomNavbarY+recognizer.view!.frame.size.height/2
      let maxY: CGFloat = pulloverOffset+recognizer.view!.frame.size.height/2
      recognizer.view!.center = CGPointMake(min(max(minX,recognizer.view!.center.x),maxX), min(max(minY,recognizer.view!.center.y),maxY))
  
      ...
  </code></pre>
  
  <p>This prevents the view from moving side to side and does stop it from moving past either top and bottom 'boundary', however, there is still some slight movement when trying to drag it past one.</p>
  
  <p>Is there a better way I can do this to <strong>completely prevent</strong> it at all from moving past the boundaries?</p>