title: Scale image based off UIPinch
body: <p>I am so confused with how to do what I need!  Any help is very appreciated!  I have an transparent image overlay that has another image behind it that has a UIPanGestureRecognizer and a UIPinchGestureRecognizer attached to it.  The top image has a completely transparent middle that serves as the "glass" view.  I am trying to crop the bottom image to the "glass" part based off pan and pinch.  (see the image below to see what i'm talking about) I have successfully taken care of the pan crop but am having issues cropping it correctly when pinch is also applied.  </p>
  
  <p>I am not using snapshotViewAfterScreenUpdates.</p>
  
  <p>Here is the code I have so far: </p>
  
  <pre><code> UIImage *snapshotImage;
  
  /* draw the image of all the views below our view */
  UIGraphicsBeginImageContextWithOptions(self.pendantImageView.bounds.size, NO, 0);
  BOOL successfulDrawHierarchy = [self.pendantImageView drawViewHierarchyInRect:self.pendantImageView.bounds afterScreenUpdates:YES];
  if ( successfulDrawHierarchy ) {
      snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
  } else {
      NSLog(@"drawViewHierarchyInRect:afterScreenUpdates: failed - there's nothing to draw...");
  }
  UIGraphicsEndImageContext();
  UIImage *croppedImage;
  if ( successfulDrawHierarchy ) {
  
      /* calculate the coordinates of the rectangle we're interested in within the returned image */
      CGRect cropRect = CGRectOffset(pendantFrame, - self.pendantImageView.frame.origin.x, - self.pendantImageView.frame.origin.y);
  
      /* draw the cropped section with a clipping region */
      UIGraphicsBeginImageContextWithOptions(cropRect.size, YES, 0);
      CGContextRef context = UIGraphicsGetCurrentContext();
      CGContextClipToRect(context, CGRectMake(0, 0, cropRect.size.width, cropRect.size.height));
      CGRect targetRectangeForCrop = CGRectMake(-cropRect.origin.x, -cropRect.origin.y, snapshotImage.size.width, snapshotImage.size.height);
      [snapshotImage drawInRect:targetRectangeForCrop];
      croppedImage = UIGraphicsGetImageFromCurrentImageContext();
      UIGraphicsEndImageContext();  
  }
  </code></pre>
  
  <p>pendantImageView is the bottom imageView and pendantFrame is the middle coords of the area i'm trying to crop to.</p>
  
  <p>Thanks in advance!</p>
  
  <p><a href="https://i.stack.imgur.com/DTSpo.png" rel="noreferrer"><img src="https://i.stack.imgur.com/DTSpo.png" alt="crop image to the area in the middle"></a></p>