title: How To set Pan Gesture Limit in swift 3
body: <p>I take two view and in that view i take image view..show..Below</p>
  
  <p><a href="https://i.stack.imgur.com/s4gf3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s4gf3.png" alt="enter image description here"></a></p>
  
  <p>i need to set limit, image centre that not going to out side of the super view..</p>
  
  <p>i am trying that code but that not work proper some time work proper..</p>
  
  <pre><code>func panImage(tap:UIPanGestureRecognizer) {
      let minx = (abs(Int((tap.view?.superview?.center.x)!)) - ((Int((tap.view?.superview?.frame.width)!))/2))
      let maxx = (abs(Int((tap.view?.superview?.center.x)!)) + ((Int((tap.view?.superview?.frame.width)!))/2))
      let miny = (abs(Int((tap.view?.superview?.center.y)!)) - ((Int((tap.view?.superview?.frame.height)!))/2))
      let maxy = (abs(Int((tap.view?.superview?.center.y)!)) + ((Int((tap.view?.superview?.frame.height)!))/2))
      let translation = tap.translation(in: tap.view)
      if(Int(tap.view!.center.x) &gt; maxx)
      {tap.view!.center.x = CGFloat(maxx)}
      if(Int(tap.view!.center.x) &lt; minx)
      {tap.view!.center.x = CGFloat(minx)}
      if(Int(tap.view!.center.y) &gt; maxy)
      {tap.view!.center.y = CGFloat(maxy)}
      if(Int(tap.view!.center.y) &lt; miny)
      {tap.view!.center.y = CGFloat(miny)}
  
      if((Int(tap.view!.center.x) &gt;= minx &amp;&amp; Int(tap.view!.center.x) &lt;= maxx ) &amp;&amp; (Int(tap.view!.center.y) &lt;= maxy &amp;&amp; Int(tap.view!.center.y) &gt;= miny))
      {
          tap.view!.center = CGPoint(x: tap.view!.center.x + translation.x, y: tap.view!.center.y + translation.y)
          tap.setTranslation(CGPoint(x: 0.0, y: 0.0), in:tap.view)
      }
  }
  </code></pre>