title: using UIImage drawInRect still renders it upside down
body: <p>I have read some posts on this website about using drawInRect instead of the CGContext draw methods. It still draws it upside down? I thought using drawInRect would print it right side up with the coordinate system originating at the top left?</p>
  
  <pre><code>-(void) drawImage:(UIImage*) image atX:(float) x andY:(float) y withWidth:(float) width andHeight:(float) height onContext:(CGContextRef) context{
  UIGraphicsPushContext(context);
  [image drawInRect:CGRectMake(x, size.height-y-height, width, height)];
  UIGraphicsPopContext();
  }
  </code></pre>
  
  <p>Notice I'm doing <code>size.height-y-height</code> and if I don't do that it doesn't go where I expect (assuming <code>drawInRect</code> using a topleft coordinate system). It renders in the correct spot with the above code but still upside down. HELP!!!!!!</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Thanks to the answer below this is the working method</p>
  
  <pre><code>-(void) drawImage:(UIImage*) image atX:(float) x andY:(float) y withWidth:(float) width andHeight:(float) height onContext:(CGContextRef) context{
  UIGraphicsPushContext(context);
  CGContextSaveGState(context); 
  CGContextTranslateCTM(context, 0, size.height);
  CGContextScaleCTM(context, 1.0, -1.0);
  [image drawInRect:CGRectMake(x, y, width, height)];
  CGContextRestoreGState(context);
  UIGraphicsPopContext();
  }
  </code></pre>