title: how to prevent view to exceed its parent bounds on Pinch Gesture - swift
body: <p>I assigned the pinch gesture to uiview:</p>
  
  <pre><code>myView.addGestureRecognizer(UIPinchGestureRecognizer(target: self, action: "handlePinch:"))
  </code></pre>
  
  <p>This function will scale the uiview:</p>
  
  <pre><code>func handlePinch(recognizer : UIPinchGestureRecognizer) {
      if let view = recognizer.view {
        view.transform = CGAffineTransformScale(view.transform, 
                                  recognizer.scale, recognizer.scale)
        recognizer.scale = 1
      }
  }
  </code></pre>
  
  <p>but the scale is <strong>not limited</strong> within the parent view. and when i try to scale it down it has also no limit, it scales till it disappears.</p>
  
  <p>The grey view is the parent</p>
  
  <p><a href="https://i.stack.imgur.com/CMY3z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CMY3z.png" alt="Desciption"></a></p>
  
  <p><strong>My Question</strong> is</p>
  
  <p>How can it be prevented from exceeding the parent frame on scale up and disappearing on scale down?</p>